ZQuest Classic Coverage Report


Directory: src/
File: src/zc/maps.cpp
Date: 2025-07-31 04:29:18
Exec Total Coverage
Lines: 4033 5072 79.5%
Functions: 274 320 85.6%
Branches: 3130 5103 61.3%

Line Branch Exec Source
1 #include "base/combo.h"
2 #include "base/handles.h"
3 #include "base/util.h"
4 #include "base/zdefs.h"
5 #include "base/general.h"
6 #include <cstring>
7 #include <assert.h>
8 #include <math.h>
9 #include <vector>
10 #include <deque>
11 #include <string>
12 #include <set>
13 #include <array>
14 #include <sstream>
15 using std::set;
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/mapscr.h"
20 #include "base/misctypes.h"
21 #include "base/initdata.h"
22 #include "zc/maps.h"
23 #include "zc/zelda.h"
24 #include "zc/zc_ffc.h"
25 #include "tiles.h"
26 #include "sprite.h"
27 #include "gui/jwin.h"
28 #include "base/zsys.h"
29 #include "subscr.h"
30 #include "zc/zc_subscr.h"
31 #include "zc/hero.h"
32 #include "zc/guys.h"
33 #include "zc/ffscript.h"
34 #include "drawing.h"
35 #include "zc/combos.h"
36 #include "zc/replay.h"
37 #include "slopes.h"
38 #include "particles.h"
39 #include <fmt/format.h>
40 #include "zc/render.h"
41 #include "iter.h"
42 #include <ranges>
43
44 // All the temporary screens (and their layers) for the currently loaded map.
45 static mapscr* temporary_screens[136*7];
46 // Set by load_region.
47 static bool screen_in_current_region[136];
48 411 static rpos_handle_t current_region_rpos_handles[136*7];
49 static bool current_region_rpos_handles_dirty;
50 static int current_region_screen_count;
51 static std::pair<const rpos_handle_t*, int> current_region_rpos_handles_scr[136];
52
53 viewport_t viewport;
54 static int viewport_sprite_uid;
55 ViewportMode viewport_mode;
56 int world_w, world_h;
57 int region_scr_dx, region_scr_dy;
58 int region_scr_count;
59 rpos_t region_max_rpos;
60 int region_num_rpos;
61 region_t cur_region, scrolling_region;
62
63 411 maze_state_t maze_state;
64 int scrolling_maze_last_solved_screen;
65
66 576 void maps_init_game_vars()
67 {
68 576 viewport = {};
69 576 viewport_mode = ViewportMode::CenterAndBound;
70 576 viewport_sprite_uid = 1;
71 576 currscr_for_passive_subscr = -1;
72 576 }
73
74 static region_ids_t current_region_ids;
75
76 14618840 static bool is_a_region(int map, int scr)
77 {
78 14618840 return get_region_id(map, scr) != 0;
79 }
80
81 2232 static bool is_same_region_id(int region_origin_scr, int map, int scr)
82 {
83
2/2
✓ Branch 0 taken 772 times.
✓ Branch 1 taken 1460 times.
2232 if (!is_a_region(map, scr)) return false;
84 1460 int region_id = get_region_id(map, region_origin_scr);
85
1/2
✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
1460 return region_id && region_id == get_region_id(map, scr);
86 2232 }
87
88 138744503 bool is_in_current_region(int map, int screen)
89 {
90
5/6
✓ Branch 0 taken 138742930 times.
✓ Branch 1 taken 1573 times.
✓ Branch 2 taken 138742930 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12213 times.
✓ Branch 5 taken 138730717 times.
138744503 return map == cur_map && screen >= 0 && screen < 128 && screen_in_current_region[screen];
91 }
92
93 69622379 bool is_in_current_region(int screen)
94 {
95
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 69622378 times.
69622379 return screen < 128 && screen_in_current_region[screen];
96 }
97
98 28999145 bool is_in_current_region(mapscr* scr)
99 {
100
4/4
✓ Branch 0 taken 28984135 times.
✓ Branch 1 taken 15010 times.
✓ Branch 2 taken 462663 times.
✓ Branch 3 taken 28521472 times.
28999145 return scr->map == cur_map && scr->screen < 128 && screen_in_current_region[scr->screen];
101 }
102
103 bool is_in_scrolling_region(int screen)
104 {
105 if (!screenscrolling) return false;
106
107 int x = screen % 16;
108 int y = screen / 16;
109 return
110 scrolling_region.origin_screen_x >= x && scrolling_region.origin_screen_x < x + scrolling_region.screen_width &&
111 scrolling_region.origin_screen_y >= y && scrolling_region.origin_screen_y < y + scrolling_region.screen_height;
112 }
113
114 9030223774 bool is_in_scrolling_region()
115 {
116 9030223774 return cur_region.screen_count > 1;
117 }
118
119 76841296 bool is_extended_height_mode()
120 {
121
2/2
✓ Branch 0 taken 76591162 times.
✓ Branch 1 taken 250134 times.
76841296 return cur_region.screen_height > 1 && (DMaps[cur_dmap].flags & dmfEXTENDEDVIEWPORT);
122 }
123
124 // Returns 0 if this is not a region.
125 15660898 int get_region_id(int map, int screen)
126 {
127
2/2
✓ Branch 0 taken 401435 times.
✓ Branch 1 taken 15259463 times.
15660898 if (screen >= 128) return 0;
128
2/2
✓ Branch 0 taken 15258363 times.
✓ Branch 1 taken 1100 times.
15259463 if (map == cur_region.map) return current_region_ids[screen];
129
130 1100 return Regions[map].get_region_id(screen);
131 15660898 }
132
133 982758 int get_current_region_id()
134 {
135 982758 return get_region_id(cur_map, cur_screen);
136 }
137
138 64229 void calculate_region(int map, int screen, region_t& region, int& region_scr_dx, int& region_scr_dy)
139 {
140 64229 region.map = map;
141
142
3/4
✓ Branch 0 taken 274 times.
✓ Branch 1 taken 63955 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 274 times.
64229 if (!(is_a_region(map, screen)) || screen >= 0x80)
143 {
144 63955 region.region_id = 0;
145 63955 region.origin_screen = screen;
146 63955 region.origin_screen_x = screen % 16;
147 63955 region.origin_screen_y = screen / 16;
148 63955 region.screen_width = 1;
149 63955 region.screen_height = 1;
150 63955 region.screen_count = 1;
151 63955 region.width = 256;
152 63955 region.height = 176;
153 63955 region_scr_dx = 0;
154 63955 region_scr_dy = 0;
155 63955 return;
156 }
157
158 274 int input_scr_x = screen % 16;
159 274 int input_scr_y = screen / 16;
160
161 // For the given screen, find the top-left corner of its region.
162 274 int origin_scr_x = input_scr_x;
163 274 int origin_scr_y = input_scr_y;
164 274 int origin_scr = screen;
165
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 372 times.
434 while (origin_scr_x > 0)
166 {
167
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 160 times.
372 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x - 1, origin_scr_y))) break;
168 160 origin_scr_x--;
169 }
170
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 414 times.
508 while (origin_scr_y > 0)
171 {
172
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 234 times.
414 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, origin_scr_y - 1))) break;
173 234 origin_scr_y--;
174 }
175 274 origin_scr = map_scr_xy_to_index(origin_scr_x, origin_scr_y);
176
177 // Now find the bottom-right corner.
178 274 int region_scr_right = origin_scr_x;
179
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 614 times.
642 while (region_scr_right < 15)
180 {
181
2/2
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 368 times.
614 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(region_scr_right + 1, origin_scr_y))) break;
182 368 region_scr_right++;
183 }
184 274 int region_scr_bottom = origin_scr_y;
185
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 832 times.
856 while (region_scr_bottom < 7)
186 {
187
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 582 times.
832 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, region_scr_bottom + 1))) break;
188 582 region_scr_bottom++;
189 }
190
191 274 region.region_id = get_region_id(map, origin_scr);
192 274 region.origin_screen = origin_scr;
193 274 region.origin_screen_x = origin_scr_x;
194 274 region.origin_screen_y = origin_scr_y;
195 274 region.screen_width = region_scr_right - origin_scr_x + 1;
196 274 region.screen_height = region_scr_bottom - origin_scr_y + 1;
197 274 region.screen_count = region.screen_width * region.screen_height;
198 274 region.width = 256 * region.screen_width;
199 274 region.height = 176 * region.screen_height;
200 274 region_scr_dx = input_scr_x - origin_scr_x;
201 274 region_scr_dy = input_scr_y - origin_scr_y;
202
203 DCHECK_RANGE_INCLUSIVE(region.screen_width, 0, 16);
204 DCHECK_RANGE_INCLUSIVE(region.screen_height, 0, 8);
205 64229 }
206
207 35861 void load_region(int dmap, int screen)
208 {
209 35861 clear_temporary_screens();
210
211 35861 int map = DMaps[dmap].map;
212 35861 current_region_ids = Regions[map].get_all_region_ids();
213
214 35861 calculate_region(map, screen, cur_region, region_scr_dx, region_scr_dy);
215 35861 cur_screen = cur_region.origin_screen;
216 35861 world_w = cur_region.width;
217 35861 world_h = cur_region.height;
218 35861 region_scr_count = cur_region.screen_count;
219 35861 region_max_rpos = (rpos_t)(cur_region.screen_count*176 - 1);
220 35861 region_num_rpos = cur_region.screen_count*176;
221 35861 scrolling_maze_last_solved_screen = 0;
222
223 35861 memset(screen_in_current_region, false, sizeof(screen_in_current_region));
224
2/2
✓ Branch 0 taken 36095 times.
✓ Branch 1 taken 35861 times.
71956 for (int x = 0; x < cur_region.screen_width; x++)
225 {
226
2/2
✓ Branch 0 taken 37105 times.
✓ Branch 1 taken 36095 times.
73200 for (int y = 0; y < cur_region.screen_height; y++)
227 {
228 37105 int screen = cur_screen + x + y*16;
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37105 times.
37105 if (screen < 136)
230 {
231 37105 screen_in_current_region[screen] = true;
232 37105 }
233 37105 }
234 36095 }
235
236 35861 mark_current_region_handles_dirty();
237 35861 }
238
239 35861 static void prepare_current_region_handles()
240 {
241 35861 current_region_rpos_handles_dirty = false;
242 35861 current_region_screen_count = 0;
243
2/2
✓ Branch 0 taken 36209 times.
✓ Branch 1 taken 35861 times.
72070 for (int y = 0; y < cur_region.screen_height; y++)
244 {
245
2/2
✓ Branch 0 taken 37105 times.
✓ Branch 1 taken 36209 times.
73314 for (int x = 0; x < cur_region.screen_width; x++)
246 {
247 37105 int screen = cur_screen + x + y*16;
248 37105 int index_start = current_region_screen_count;
249
2/2
✓ Branch 0 taken 37105 times.
✓ Branch 1 taken 259735 times.
296840 for (int layer = 0; layer <= 6; layer++)
250 {
251 259735 mapscr* scr = get_scr_layer(screen, layer);
252
2/2
✓ Branch 0 taken 84587 times.
✓ Branch 1 taken 175148 times.
259735 if (!scr->is_valid())
253 {
254
1/2
✓ Branch 0 taken 175148 times.
✗ Branch 1 not taken.
175148 if (layer == 0) break;
255 175148 continue;
256 }
257
258 84587 rpos_t base_rpos = POS_TO_RPOS(0, get_region_relative_dx(screen), get_region_relative_dy(screen));
259 84587 current_region_rpos_handles[current_region_screen_count] = {scr, screen, layer, base_rpos, 0};
260 84587 current_region_screen_count += 1;
261 84587 }
262
263 37105 int num_handles_for_scr = current_region_screen_count - index_start;
264 37105 current_region_rpos_handles_scr[screen] = {&current_region_rpos_handles[index_start], num_handles_for_scr};
265 37105 }
266 36209 }
267 35861 }
268
269 1783401621 std::tuple<const rpos_handle_t*, int> get_current_region_handles()
270 {
271 DCHECK(!current_region_rpos_handles_dirty);
272 1783401621 return {current_region_rpos_handles, current_region_screen_count};
273 }
274
275 11074905 std::tuple<const rpos_handle_t*, int> get_current_region_handles(mapscr* scr)
276 {
277 DCHECK(!current_region_rpos_handles_dirty);
278
2/4
✓ Branch 0 taken 11074905 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11074905 times.
11074905 if (scr == special_warp_return_scr || current_region_rpos_handles_dirty)
279 return {nullptr, 0};
280
281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11074905 times.
11074905 if (cur_screen >= 0x80)
282 {
283 DCHECK(scr == origin_scr);
284 return {nullptr, 0};
285 }
286
287 DCHECK(is_in_current_region(scr));
288 11074905 return current_region_rpos_handles_scr[scr->screen];
289 11074905 }
290
291 35861 void mark_current_region_handles_dirty()
292 {
293 35861 current_region_rpos_handles_dirty = true;
294 35861 }
295
296 36999 void clear_temporary_screens()
297 {
298
2/2
✓ Branch 0 taken 35223048 times.
✓ Branch 1 taken 36999 times.
35260047 for (int i = 0; i < 136*7; i++)
299 {
300
2/2
✓ Branch 0 taken 35168427 times.
✓ Branch 1 taken 54621 times.
35223048 if (temporary_screens[i])
301 {
302 54621 free(temporary_screens[i]);
303 54621 temporary_screens[i] = NULL;
304 54621 }
305 35223048 }
306
307 36999 origin_scr = nullptr;
308 36999 hero_scr = nullptr;
309 36999 }
310
311 27962 std::vector<mapscr*> take_temporary_scrs()
312 {
313
1/2
✓ Branch 0 taken 27962 times.
✗ Branch 1 not taken.
27962 std::vector<mapscr*> screens(temporary_screens, temporary_screens + 136*7);
314
2/2
✓ Branch 0 taken 27962 times.
✓ Branch 1 taken 26619824 times.
26647786 for (int i = 0; i < 136*7; i++)
315 26619824 temporary_screens[i] = nullptr;
316
317 27962 return screens;
318
1/2
✓ Branch 0 taken 27962 times.
✗ Branch 1 not taken.
27962 }
319
320 14552739 void calculate_viewport(viewport_t& viewport, int dmap, int screen, int world_w, int world_h, int x, int y)
321 {
322 // TODO: In future, maybe add x/y centering offsets to zscript (Viewport->TargetXOffset/Viewport->TargetYOffset).
323
324
2/2
✓ Branch 0 taken 14506157 times.
✓ Branch 1 taken 46582 times.
14552739 bool extended_height_mode = (DMaps[dmap].flags & dmfEXTENDEDVIEWPORT) && world_h > 176;
325 14552739 viewport.w = 256;
326 14552739 viewport.h = 176 + (extended_height_mode ? 56 : 0);
327
328
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 14552379 times.
14552739 if (viewport_mode == ViewportMode::Script)
329 360 return;
330
331
2/2
✓ Branch 0 taken 46162 times.
✓ Branch 1 taken 14506217 times.
14552379 if (!is_a_region(DMaps[dmap].map, screen))
332 {
333 14506217 viewport.x = 0;
334 14506217 viewport.y = 0;
335 14506217 }
336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46162 times.
46162 else if (viewport_mode == ViewportMode::CenterAndBound)
337 {
338 // Clamp the viewport to the edges of the region.
339
6/6
✓ Branch 0 taken 8568 times.
✓ Branch 1 taken 37594 times.
✓ Branch 2 taken 6788 times.
✓ Branch 3 taken 39374 times.
✓ Branch 4 taken 8568 times.
✓ Branch 5 taken 30806 times.
46162 viewport.x = CLAMP(0, world_w - viewport.w, x - viewport.w/2);
340
6/6
✓ Branch 0 taken 11856 times.
✓ Branch 1 taken 34306 times.
✓ Branch 2 taken 5650 times.
✓ Branch 3 taken 40512 times.
✓ Branch 4 taken 11856 times.
✓ Branch 5 taken 28656 times.
46162 viewport.y = CLAMP(0, world_h - viewport.h, y - viewport.h/2);
341 46162 }
342 else if (viewport_mode == ViewportMode::Center)
343 {
344 viewport.x = x - viewport.w/2;
345 viewport.y = y - viewport.h/2;
346 }
347 14552739 }
348
349 14552228 sprite* get_viewport_sprite()
350 {
351 14552228 sprite* spr = sprite::getByUID(viewport_sprite_uid);
352
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14552222 times.
14552228 if (!spr)
353 {
354 6 viewport_sprite_uid = 1; // Hero uid.
355 6 spr = &Hero;
356 6 }
357
358 14552228 return spr;
359 }
360
361 6 void set_viewport_sprite(sprite* spr)
362 {
363 6 viewport_sprite_uid = spr->uid;
364 6 }
365
366 14524266 void update_viewport()
367 {
368 14524266 sprite* spr = get_viewport_sprite();
369 14524266 int x = spr->x + spr->txsz*16/2;
370 14524266 int y = spr->y + spr->tysz*16/2;
371 14524266 calculate_viewport(viewport, cur_dmap, cur_screen, world_w, world_h, x, y);
372 14524266 }
373
374 14312110 void update_heroscr()
375 {
376 void playLevelMusic();
377
378 14312110 int x = vbound(Hero.getX().getInt(), 0, world_w - 1);
379 14312110 int y = vbound(Hero.getY().getInt(), 0, world_h - 1);
380 14312110 int dx = x / 256;
381 14312110 int dy = y / 176;
382 14312110 int new_screen = cur_screen + dx + dy * 16;
383
2/2
✓ Branch 0 taken 14304348 times.
✓ Branch 1 taken 7762 times.
14312110 if (maze_state.active == 1)
384 7762 new_screen = maze_state.scr->screen;
385
7/12
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 14311894 times.
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 216 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 216 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 216 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 216 times.
14312110 if (hero_screen != new_screen && dx >= 0 && dy >= 0 && dx < 16 && dy < 8 && is_in_current_region(new_screen))
386 {
387 216 region_scr_dx = dx;
388 216 region_scr_dy = dy;
389 216 hero_screen = new_screen;
390 216 prev_hero_scr = hero_scr;
391 216 hero_scr = get_scr(hero_screen);
392 216 Hero.screen_spawned = hero_screen;
393 216 playLevelMusic();
394 216 }
395
1/2
✓ Branch 0 taken 14312110 times.
✗ Branch 1 not taken.
14312110 if (game->get_regionmapping() == REGION_MAPPING_PHYSICAL)
396 mark_visited(new_screen); // Mark each screen the hero steps foot in as visited
397 14312110 }
398
399 4722 mapscr* determine_hero_screen_from_coords()
400 {
401 4722 int x = vbound(Hero.getX().getInt(), 0, world_w - 1);
402 4722 int y = vbound(Hero.getY().getInt(), 0, world_h - 1);
403 4722 int dx = x / 256;
404 4722 int dy = y / 176;
405 4722 return get_scr(cur_screen + dx + dy * 16);
406 }
407
408 26932 bool edge_of_region(direction dir)
409 {
410
2/2
✓ Branch 0 taken 26852 times.
✓ Branch 1 taken 80 times.
26932 if (!is_in_scrolling_region()) return true;
411
412 80 int screen_x = hero_screen % 16;
413 80 int screen_y = hero_screen / 16;
414
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2 times.
80 if (dir == up) screen_y -= 1;
415
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 10 times.
80 if (dir == down) screen_y += 1;
416
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 if (dir == left) screen_x -= 1;
417
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 38 times.
80 if (dir == right) screen_x += 1;
418
4/8
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 80 times.
✗ Branch 7 not taken.
80 if (screen_x < 0 || screen_x > 16 || screen_y < 0 || screen_y > 8) return true;
419 80 return !is_in_current_region(map_scr_xy_to_index(screen_x, screen_y));
420 26932 }
421
422 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
423 // Coordinates are clamped to the world bounds.
424 212215670 int get_screen_for_world_xy(int x, int y)
425 {
426
2/2
✓ Branch 0 taken 189426058 times.
✓ Branch 1 taken 22789612 times.
212215670 if (!is_in_scrolling_region())
427 189426058 return cur_screen;
428
429 22789612 int dx = std::clamp(x, 0, world_w - 1) / 256;
430 22789612 int dy = std::clamp(y, 0, world_h - 1) / 176;
431 22789612 int origin_screen_x = cur_screen % 16;
432 22789612 int origin_screen_y = cur_screen / 16;
433 22789612 int scr_x = origin_screen_x + dx;
434 22789612 int scr_y = origin_screen_y + dy;
435 22789612 return map_scr_xy_to_index(scr_x, scr_y);
436 212215670 }
437
438 32518504 int get_screen_for_rpos(rpos_t rpos)
439 {
440 32518504 int origin_screen_x = cur_screen % 16;
441 32518504 int origin_screen_y = cur_screen / 16;
442 32518504 int screen = static_cast<int32_t>(rpos) / 176;
443 32518504 int scr_x = origin_screen_x + screen%cur_region.screen_width;
444 32518504 int scr_y = origin_screen_y + screen/cur_region.screen_width;
445 32518504 return map_scr_xy_to_index(scr_x, scr_y);
446 }
447
448 774825900 rpos_handle_t get_rpos_handle(rpos_t rpos, int layer)
449 {
450 DCHECK_LAYER_ZERO_INDEX(layer);
451
2/2
✓ Branch 0 taken 742445356 times.
✓ Branch 1 taken 32380544 times.
774825900 if (!is_in_scrolling_region())
452 742445356 return {get_scr_layer(cur_screen, layer), cur_screen, layer, rpos, RPOS_TO_POS(rpos)};
453 32380544 int screen = get_screen_for_rpos(rpos);
454 32380544 mapscr* scr = get_scr_layer(screen, layer);
455 32380544 return {scr, screen, layer, rpos, RPOS_TO_POS(rpos)};
456 774825900 }
457
458 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
459 // Coordinates are clamped to the world bounds.
460 3504314196 rpos_handle_t get_rpos_handle_for_world_xy(int x, int y, int layer)
461 {
462 3504314196 x = std::clamp(x, 0, world_w - 1);
463 3504314196 y = std::clamp(y, 0, world_h - 1);
464
465 DCHECK_LAYER_ZERO_INDEX(layer);
466
2/2
✓ Branch 0 taken 3476577024 times.
✓ Branch 1 taken 27737172 times.
3504314196 if (!is_in_scrolling_region())
467 {
468 3476577024 int pos = COMBOPOS(x, y);
469 3476577024 return {get_scr_layer(cur_screen, layer), cur_screen, layer, (rpos_t)pos, pos};
470 }
471 27737172 return get_rpos_handle(COMBOPOS_REGION(x, y), layer);
472 3504314196 }
473
474 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
475 44 rpos_handle_t get_rpos_handle_for_screen(int screen, int layer, int pos)
476 {
477 DCHECK_LAYER_ZERO_INDEX(layer);
478 44 return {get_scr_layer(screen, layer), screen, layer, POS_TO_RPOS(pos, screen), pos};
479 }
480
481 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
482 // Use this instead of the other `get_pos_handle_for_screen` if you already have a reference to the screen.
483 62245 rpos_handle_t get_rpos_handle_for_scr(mapscr* scr, int layer, int pos)
484 {
485 DCHECK_LAYER_ZERO_INDEX(layer);
486 62245 return {scr, scr->screen, layer, POS_TO_RPOS(pos, scr->screen), pos};
487 }
488
489 25156040 void change_rpos_handle_layer(rpos_handle_t& rpos_handle, int layer)
490 {
491 DCHECK_LAYER_ZERO_INDEX(layer);
492 25156040 rpos_handle.layer = layer;
493 25156040 rpos_handle.scr = get_scr_layer(rpos_handle.screen, layer);
494 25156040 }
495
496 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
497 // Coordinates are clamped to the world bounds.
498 52808 combined_handle_t get_combined_handle_for_world_xy(int x, int y, int layer)
499 {
500 DCHECK_LAYER_ZERO_INDEX(layer);
501
502 52808 x = std::clamp(x, 0, world_w - 1);
503 52808 y = std::clamp(y, 0, world_h - 1);
504
505 52808 auto maybe_ffc_handle = getFFCAt(x, y);
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (maybe_ffc_handle)
507 return maybe_ffc_handle.value();
508
509 52808 auto rpos = COMBOPOS_REGION_B(x, y);
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (rpos == rpos_t::None)
511 return rpos_handle_t();
512 52808 return get_rpos_handle(rpos, layer);
513 52808 }
514
515 // These functions all return _temporary_ screens. Any modifications made to them (either by the engine
516 // directly or via zscript) only last until the next area is loaded (via loadscr).
517
518 // Returns the screen containing the (x, y) world position.
519 1634589227 mapscr* get_scr_for_world_xy(int x, int y)
520 {
521 // Quick path, but should work the same without.
522
2/2
✓ Branch 0 taken 1623456227 times.
✓ Branch 1 taken 11133000 times.
1634589227 if (!is_in_scrolling_region()) return origin_scr;
523 11133000 return get_scr(get_screen_for_world_xy(x, y));
524 1634589227 }
525
526 24523958 mapscr* get_scr_for_rpos(rpos_t rpos)
527 {
528 // Quick path, but should work the same without.
529
2/2
✓ Branch 0 taken 24386012 times.
✓ Branch 1 taken 137946 times.
24523958 if (!is_in_scrolling_region()) return origin_scr;
530 137946 return get_scr(get_screen_for_rpos(rpos));
531 24523958 }
532
533 14 mapscr* get_scr_for_rpos_layer(rpos_t rpos, int layer)
534 {
535 14 return get_scr_layer(get_screen_for_rpos(rpos), layer);
536 }
537
538 // Note: layer=0 is the base screen, 1 is the first layer, etc.
539 2309648558 mapscr* get_scr_for_world_xy_layer(int x, int y, int layer)
540 {
541 DCHECK_LAYER_ZERO_INDEX(layer);
542
2/2
✓ Branch 0 taken 2298228560 times.
✓ Branch 1 taken 11419998 times.
2309648558 if (!is_in_scrolling_region()) return get_scr_layer(cur_screen, layer);
543
2/2
✓ Branch 0 taken 708934 times.
✓ Branch 1 taken 10711064 times.
11419998 return layer == 0 ?
544 708934 get_scr_for_world_xy(x, y) :
545 10711064 get_scr_layer(get_screen_for_world_xy(x, y), layer);
546 2309648558 }
547
548 1834600229 int get_region_screen_offset(int screen)
549 {
550 1834600229 return get_region_relative_dx(screen) + get_region_relative_dy(screen) * cur_region.screen_width;
551 }
552
553 654676699 int get_screen_for_region_index_offset(int offset)
554 {
555 654676699 int scr_dx = offset % cur_region.screen_width;
556 654676699 int scr_dy = offset / cur_region.screen_width;
557 654676699 int screen = cur_screen + scr_dx + scr_dy*16;
558 654676699 return screen;
559 }
560
561 654492862 mapscr* get_scr_for_region_index_offset(int offset)
562 {
563 654492862 int screen = get_screen_for_region_index_offset(offset);
564 654492862 return get_scr(screen);
565 }
566
567 // The screen at (map, screen) must exist.
568 1421828894 mapscr* get_scr(int map, int screen)
569 {
570 1421828894 mapscr* scr = get_scr_maybe(map, screen);
571
1/2
✓ Branch 0 taken 1421828894 times.
✗ Branch 1 not taken.
1421828894 CHECK(scr);
572 1421828894 return scr;
573 }
574
575 837417173 mapscr* get_scr(int screen)
576 {
577 837417173 return get_scr(cur_map, screen);
578 }
579
580 // Returns null if active screen does not exist.
581 1451373925 mapscr* get_scr_maybe(int map, int screen)
582 {
583 DCHECK_RANGE_INCLUSIVE(screen, 0, 135);
584
585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1451373925 times.
1451373925 if (map == cur_map)
586 {
587
2/2
✓ Branch 0 taken 1430598993 times.
✓ Branch 1 taken 20774932 times.
1451373925 if (screen == cur_screen)
588 1430598993 return origin_scr;
589
590 20774932 int index = screen*7;
591
2/2
✓ Branch 0 taken 20763842 times.
✓ Branch 1 taken 11090 times.
20774932 if (temporary_screens[index])
592 20763842 return temporary_screens[index];
593
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11090 times.
11090 if (screen == home_screen)
595 return special_warp_return_scr;
596 11090 }
597
598
3/6
✓ Branch 0 taken 11090 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11090 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11090 times.
11090 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
599 {
600 11090 int index = screen*7;
601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11090 times.
11090 if (FFCore.ScrollingScreensAll[index])
602 11090 return FFCore.ScrollingScreensAll[index];
603 }
604
605 return nullptr;
606 1451373925 }
607
608 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
609 7067170355 mapscr* get_scr_layer(int map, int screen, int layer)
610 {
611 DCHECK_LAYER_ZERO_INDEX(layer);
612
2/2
✓ Branch 0 taken 6485185545 times.
✓ Branch 1 taken 581984810 times.
7067170355 if (layer == 0)
613 581984810 return get_scr(map, screen);
614
615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485185545 times.
6485185545 if (map == cur_map)
616 {
617 6485185545 int index = screen*7 + layer;
618
2/2
✓ Branch 0 taken 6485117145 times.
✓ Branch 1 taken 68400 times.
6485185545 if (temporary_screens[index])
619 6485117145 return temporary_screens[index];
620
621
2/2
✓ Branch 0 taken 1860 times.
✓ Branch 1 taken 66540 times.
68400 if (screen == home_screen)
622 1860 return &special_warp_return_scrs[layer];
623 66540 }
624
625
1/2
✓ Branch 0 taken 66540 times.
✗ Branch 1 not taken.
66540 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
626 {
627 66540 int index = screen*7 + layer;
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66540 times.
66540 if (FFCore.ScrollingScreensAll[index])
629 66540 return FFCore.ScrollingScreensAll[index];
630 }
631
632 NOTREACHED();
633 7067170355 }
634
635 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
636 6667825923 mapscr* get_scr_layer(int screen, int layer)
637 {
638 6667825923 return get_scr_layer(cur_map, screen, layer);
639 }
640
641 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
642 // Return nullptr if screen is not valid.
643 397270581 mapscr* get_scr_layer_valid(int screen, int layer)
644 {
645
2/2
✓ Branch 0 taken 78420547 times.
✓ Branch 1 taken 318850034 times.
397270581 if (mapscr* scr = get_scr_layer(cur_map, screen, layer); scr->is_valid())
646 78420547 return scr;
647 318850034 return nullptr;
648 397270581 }
649
650 401 mapscr* get_scr_current_region_dir(int screen, direction dir)
651 {
652 401 int x = get_region_relative_dx(screen);
653 401 int y = get_region_relative_dy(screen);
654
3/4
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 330 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 71 times.
401 if (dir == left && x == 0)
655 71 return nullptr;
656
3/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 238 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
330 if (dir == right && x == 15)
657 return nullptr;
658
3/4
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 281 times.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
330 if (dir == down && y == 7)
659 return nullptr;
660
3/4
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 141 times.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
330 if (dir == up && y == 0)
661 189 return nullptr;
662
663 141 screen = screen_index_direction(screen, dir);
664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 141 times.
141 if (is_in_current_region(screen))
665 return get_scr(screen);
666
667 141 return nullptr;
668 401 }
669
670 183837 ffc_handle_t get_ffc_handle(ffc_id_t id)
671 {
672 183837 uint8_t screen = get_screen_for_region_index_offset(id / MAXFFCS);
673 183837 uint8_t i = id % MAXFFCS;
674 183837 mapscr* scr = get_scr(screen);
675 183837 ffcdata* ffc = &scr->getFFC(id % MAXFFCS);
676 183837 return {scr, screen, id, i, ffc};
677 }
678
679 34565 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen, int x, int y)
680 {
681 34565 x += get_region_relative_dx(screen) * 256;
682 34565 y += get_region_relative_dy(screen) * 176;
683 34565 return {x, y};
684 }
685
686 1049508 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen)
687 {
688 1049508 int x = get_region_relative_dx(screen) * 256;
689 1049508 int y = get_region_relative_dy(screen) * 176;
690 1049508 return {x, y};
691 }
692
693 12146604124 int32_t COMBOPOS(int32_t x, int32_t y)
694 {
695 DCHECK(x >= 0 && x < 256 && y >= 0 && y < 176);
696 12146604124 return (y & 0xF0) + (x >> 4);
697 }
698 int32_t COMBOPOS_B(int32_t x, int32_t y)
699 {
700 if(unsigned(x) >= 256 || unsigned(y) >= 176)
701 return -1;
702 return (y & 0xF0) + (x >> 4);
703 }
704 3337221184 int32_t COMBOX(int32_t pos)
705 {
706 3337221184 return pos % 16 * 16;
707 }
708 3337221184 int32_t COMBOY(int32_t pos)
709 {
710 3337221184 return pos & 0xF0;
711 }
712
713 112660953 rpos_t COMBOPOS_REGION(int32_t x, int32_t y)
714 {
715
2/2
✓ Branch 0 taken 84108307 times.
✓ Branch 1 taken 28552646 times.
112660953 if (!is_in_scrolling_region())
716 84108307 return (rpos_t) COMBOPOS(x, y);
717
718 DCHECK(is_in_world_bounds(x, y));
719 28552646 int scr_dx = x / (16*16);
720 28552646 int scr_dy = y / (11*16);
721 28552646 int pos = COMBOPOS(x%256, y%176);
722 28552646 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
723 112660953 }
724 6307740944 rpos_t COMBOPOS_REGION_B(int32_t x, int32_t y)
725 {
726
2/2
✓ Branch 0 taken 1397607 times.
✓ Branch 1 taken 6306343337 times.
6307740944 if (!is_in_world_bounds(x, y))
727 1397607 return rpos_t::None;
728
729 6306343337 int scr_dx = x / (16*16);
730 6306343337 int scr_dy = y / (11*16);
731 6306343337 int pos = COMBOPOS(x%256, y%176);
732 6306343337 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
733 6307740944 }
734 25146992 std::pair<int32_t, int32_t> COMBOXY_REGION(rpos_t rpos)
735 {
736 25146992 int scr_index = static_cast<int32_t>(rpos) / 176;
737 25146992 int scr_dx = scr_index % cur_region.screen_width;
738 25146992 int scr_dy = scr_index / cur_region.screen_width;
739 25146992 int pos = RPOS_TO_POS(rpos);
740 25146992 int x = scr_dx*16*16 + COMBOX(pos);
741 25146992 int y = scr_dy*11*16 + COMBOY(pos);
742 25146992 return {x, y};
743 }
744 60396 int32_t COMBOX_REGION(rpos_t rpos)
745 {
746 60396 auto [x, y] = COMBOXY_REGION(rpos);
747 60396 return x;
748 }
749 12225 int32_t COMBOY_REGION(rpos_t rpos)
750 {
751 12225 auto [x, y] = COMBOXY_REGION(rpos);
752 12225 return y;
753 }
754
755 70177 rpos_t COMBOPOS_REGION_INDEX(int32_t x, int32_t y)
756 {
757 DCHECK(is_in_world_bounds(x, y));
758
1/2
✓ Branch 0 taken 70177 times.
✗ Branch 1 not taken.
70177 if (!is_in_scrolling_region())
759 70177 return (rpos_t)(x + y * 16);
760
761 int scr_dx = x / 16;
762 int scr_dy = y / 11;
763 x %= 16;
764 y %= 11;
765 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + x + y * 16);
766 70177 }
767 70632 std::pair<int32_t, int32_t> COMBOXY_REGION_INDEX(rpos_t rpos)
768 {
769 70632 int scr_index = static_cast<int32_t>(rpos) / 176;
770 70632 int scr_dx = scr_index % cur_region.screen_width;
771 70632 int scr_dy = scr_index / cur_region.screen_width;
772 70632 int pos = RPOS_TO_POS(rpos);
773 70632 int x = scr_dx*16 + pos%16;
774 70632 int y = scr_dy*11 + pos/16;
775 70632 return {x, y};
776 }
777
778 82530377 int32_t mapind(int32_t map, int32_t scr)
779 {
780 82530377 return map * MAPSCRSNORMAL + scr;
781 }
782
783 FONT *get_zc_font(int index);
784
785 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
786 extern movingblock mblock2; //mblock[4]?
787 extern portal mirror_portal;
788
789 void Z_message_d(const char *format,...)
790 {
791 #ifdef _DEBUG
792 char buf[512];
793 va_list ap;
794 va_start(ap, format);
795 vsprintf(buf, format, ap);
796 va_end(ap);
797
798 al_trace("%s",buf);
799 #else
800 format=format;
801 #endif
802 }
803
804
805
806 bool checktrigger=false;
807
808 void debugging_box(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
809 {
810 //reference/optimization: the start of the unused drawing command index can now be queried. -Gleeok
811 int32_t index = script_drawing_commands.GetNext();
812
813 if(index < 0)
814 return;
815
816 int32_t *sdci = &script_drawing_commands[index][0];
817
818 sdci[0] = RECTR;
819 sdci[1] = 30000;
820 sdci[2] = x1*10000;
821 sdci[3] = y1*10000;
822 sdci[4] = x2*10000;
823 sdci[5] = y2*10000;
824 sdci[6] = 10000;
825 sdci[7] = 10000;
826 sdci[8] = 0;
827 sdci[9] = 0;
828 sdci[10] = 0;
829 sdci[11] = 10000;
830 sdci[12] = 1280000;
831 }
832
833 void clear_dmap(word i)
834 {
835 DMaps[i].clear();
836 }
837
838 void clear_dmaps()
839 {
840 for(int32_t i=0; i<MAXDMAPS; i++)
841 {
842 clear_dmap(i);
843 }
844 }
845
846 223811204 int32_t isdungeon(int32_t dmap, int32_t screen)
847 {
848
2/2
✓ Branch 0 taken 223765524 times.
✓ Branch 1 taken 45680 times.
223811204 if (dmap < 0) dmap = cur_dmap;
849
850 // dungeons can have any dlevel above 0
851
2/2
✓ Branch 0 taken 122592210 times.
✓ Branch 1 taken 101218994 times.
223811204 if((DMaps[dmap].type&dmfTYPE) == dmDNGN)
852 {
853
2/2
✓ Branch 0 taken 9961 times.
✓ Branch 1 taken 101209033 times.
101218994 if (get_canonical_scr(cur_map, screen)->flags6&fCAVEROOM)
854 9961 return 0;
855
856 101209033 return 1;
857 }
858
859 // dlevels that aren't dungeons are caves
860
2/2
✓ Branch 0 taken 36827 times.
✓ Branch 1 taken 122555383 times.
122592210 if (get_canonical_scr(cur_map, screen)->flags6&fDUNGEONROOM)
861 36827 return 1;
862
863 122555383 return 0;
864 223811204 }
865
866 39939660 int32_t isdungeon(int32_t screen)
867 {
868 39939660 return isdungeon(cur_dmap, screen);
869 }
870
871 183744600 int32_t isdungeon()
872 {
873 183744600 return isdungeon(cur_dmap, hero_screen);
874 }
875
876 88932 bool canPermSecret(int32_t dmap, int32_t screen)
877 {
878
2/2
✓ Branch 0 taken 13908 times.
✓ Branch 1 taken 75024 times.
88932 return (!isdungeon(dmap, screen) || get_qr(qr_DUNGEON_DMAPS_PERM_SECRETS));
879 }
880
881 1376423623 int32_t MAPCOMBO(int32_t x, int32_t y)
882 {
883 1376423623 x = vbound(x, 0, world_w-1);
884 1376423623 y = vbound(y, 0, world_h-1);
885 1376423623 int pos = COMBOPOS(x%256, y%176);
886 1376423623 mapscr* scr = get_scr_for_world_xy(x, y);
887 1376423623 return scr->data[pos];
888 }
889
890 //specific layers 1 to 6
891 1710334462 int32_t MAPCOMBOL(int32_t layer,int32_t x,int32_t y)
892 {
893 DCHECK(layer >= 1 && layer <= 6);
894
3/4
✓ Branch 0 taken 1689977436 times.
✓ Branch 1 taken 20357026 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1689977436 times.
1710334462 if (!is_in_world_bounds(x, y) || layer <= 0)
895 20357026 return 0;
896
897 1689977436 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
898
2/2
✓ Branch 0 taken 497648153 times.
✓ Branch 1 taken 1192329283 times.
1689977436 if (!m->is_valid())
899 1192329283 return 0;
900
901 497648153 int pos = COMBOPOS(x%256, y%176);
902 497648153 return m->data[pos];
903 1710334462 }
904
905 int32_t MAPCSETL(int32_t layer,int32_t x,int32_t y)
906 {
907 DCHECK(layer >= 1 && layer <= 6);
908 if (!is_in_world_bounds(x, y) || layer <= 0)
909 return 0;
910
911 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
912 if (!m->is_valid())
913 return 0;
914
915 int pos = COMBOPOS(x%256, y%176);
916 return m->cset[pos];
917 }
918
919 189180 int32_t MAPFLAGL(int32_t layer,int32_t x,int32_t y)
920 {
921 DCHECK(layer >= 1 && layer <= 6);
922
2/4
✓ Branch 0 taken 189180 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189180 times.
189180 if (!is_in_world_bounds(x, y) || layer <= 0)
923 return 0;
924
925 189180 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
926
2/2
✓ Branch 0 taken 148786 times.
✓ Branch 1 taken 40394 times.
189180 if (!m->is_valid())
927 40394 return 0;
928
929 148786 int pos = COMBOPOS(x%256, y%176);
930 148786 return m->sflag[pos];
931 189180 }
932
933 6281 int32_t COMBOTYPEL(int32_t layer,int32_t x,int32_t y)
934 {
935 DCHECK(layer >= 1 && layer <= 6);
936
2/4
✓ Branch 0 taken 6281 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6281 times.
6281 if (!is_in_world_bounds(x, y) || layer <= 0)
937 return 0;
938
939 6281 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
940
2/2
✓ Branch 0 taken 5809 times.
✓ Branch 1 taken 472 times.
6281 if (!m->is_valid())
941 472 return 0;
942
943 5809 int pos = COMBOPOS(x%256, y%176);
944 5809 return combobuf[m->data[pos]].type;
945 6281 }
946
947 189180 int32_t MAPCOMBOFLAGL(int32_t layer,int32_t x,int32_t y)
948 {
949 DCHECK(layer >= 1 && layer <= 6);
950
2/4
✓ Branch 0 taken 189180 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189180 times.
189180 if (!is_in_world_bounds(x, y) || layer <= 0)
951 return 0;
952
953 189180 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
954
2/2
✓ Branch 0 taken 148786 times.
✓ Branch 1 taken 40394 times.
189180 if (!m->is_valid())
955 40394 return 0;
956
957 148786 int pos = COMBOPOS(x%256, y%176);
958 148786 return combobuf[m->data[pos]].flag;
959 189180 }
960
961
962 // True if the FFC covers x, y and is not ethereal or a changer.
963 2467447696 bool ffcIsAt(const ffc_handle_t& ffc_handle, int32_t x, int32_t y)
964 {
965
2/2
✓ Branch 0 taken 746638870 times.
✓ Branch 1 taken 1720808826 times.
2467447696 if (ffc_handle.data()<=0)
966 746638870 return false;
967
968
2/2
✓ Branch 0 taken 300884516 times.
✓ Branch 1 taken 1419924310 times.
1720808826 if((ffc_handle.ffc->flags&(ffc_changer|ffc_ethereal))!=0)
969 300884516 return false;
970
971 1419924310 int32_t fx=ffc_handle.ffc->x.getInt();
972
4/4
✓ Branch 0 taken 976336659 times.
✓ Branch 1 taken 443587651 times.
✓ Branch 2 taken 866205591 times.
✓ Branch 3 taken 110131068 times.
1419924310 if(x<fx || x>fx+(ffc_handle.scr->ffEffectWidth(ffc_handle.i)-1)) // FFC sizes are weird.
973 1309793242 return false;
974
975 110131068 int32_t fy=ffc_handle.ffc->y.getInt();
976
4/4
✓ Branch 0 taken 80147059 times.
✓ Branch 1 taken 29984009 times.
✓ Branch 2 taken 60079259 times.
✓ Branch 3 taken 20067800 times.
110131068 if(y<fy || y>fy+(ffc_handle.scr->ffEffectHeight(ffc_handle.i)-1))
977 90063268 return false;
978
979 20067800 return true;
980 2467447696 }
981
982 999317835 int32_t MAPFFCOMBO(int32_t x,int32_t y)
983 {
984
2/2
✓ Branch 0 taken 13163663 times.
✓ Branch 1 taken 986154172 times.
999317835 if (auto ffc_handle = getFFCAt(x, y))
985 13163663 return ffc_handle->data();
986 986154172 return 0;
987 999317835 }
988
989 207232 int32_t MAPCSET(int32_t x, int32_t y)
990 {
991
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 207232 times.
207232 if (!is_in_world_bounds(x, y))
992 return 0;
993 207232 mapscr* scr = get_scr_for_world_xy(x, y);
994 207232 int pos = COMBOPOS(x%256, y%176);
995 207232 return scr->cset[pos];
996 207232 }
997
998 73652569 int32_t MAPFLAG(int32_t x, int32_t y)
999 {
1000
2/2
✓ Branch 0 taken 28140 times.
✓ Branch 1 taken 73624429 times.
73652569 if (!is_in_world_bounds(x, y))
1001 28140 return 0;
1002 73624429 mapscr* scr = get_scr_for_world_xy(x, y);
1003 73624429 int pos = COMBOPOS(x%256, y%176);
1004 73624429 return scr->sflag[pos];
1005 73652569 }
1006
1007 165678107 int32_t COMBOTYPE(int32_t x,int32_t y)
1008 {
1009 165678107 int32_t b=1;
1010
2/2
✓ Branch 0 taken 96747518 times.
✓ Branch 1 taken 68930589 times.
165678107 if(x&8) b<<=2;
1011
2/2
✓ Branch 0 taken 83447284 times.
✓ Branch 1 taken 82230823 times.
165678107 if(y&8) b<<=1;
1012
1013
2/2
✓ Branch 0 taken 331349176 times.
✓ Branch 1 taken 165670431 times.
497019607 for (int32_t i = 0; i <= 1; ++i)
1014 {
1015
2/2
✓ Branch 0 taken 320197524 times.
✓ Branch 1 taken 11151652 times.
331349176 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1016 {
1017
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 320197524 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
320197524 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x, y, i)) return cNONE;
1018 320197524 }
1019 else
1020 {
1021
4/4
✓ Branch 0 taken 10828 times.
✓ Branch 1 taken 11140824 times.
✓ Branch 2 taken 3152 times.
✓ Branch 3 taken 7676 times.
11151652 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x, y, i)) return cNONE;
1022 }
1023 331341500 }
1024
1025 165670431 newcombo const& cmb = combobuf[MAPCOMBO(x,y)];
1026
5/6
✓ Branch 0 taken 3652838 times.
✓ Branch 1 taken 162017593 times.
✓ Branch 2 taken 3069902 times.
✓ Branch 3 taken 582936 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3069902 times.
165670431 if (cmb.type == cWATER && (cmb.walk&b) && ((cmb.walk>>4)&b))
1027 {
1028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3069902 times.
3069902 if(cmb.usrflags&cflag4) return cSHALLOWWATER;
1029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3069902 times.
3069902 if(cmb.usrflags&cflag3) return cNONE;
1030 3069902 }
1031 165670431 return cmb.type;
1032 165678107 }
1033
1034 50213349 int32_t FFCOMBOTYPE(int32_t x,int32_t y)
1035 {
1036 50213349 return combobuf[MAPFFCOMBO(x,y)].type;
1037 }
1038
1039 4971968 int32_t FFORCOMBO(int32_t x, int32_t y)
1040 {
1041
2/2
✓ Branch 0 taken 58516 times.
✓ Branch 1 taken 4913452 times.
4971968 if (auto ffc_handle = getFFCAt(x, y))
1042 58516 return ffc_handle->data();
1043
1044 4913452 return MAPCOMBO(x,y);
1045 4971968 }
1046
1047 int32_t FFORCOMBOTYPE(int32_t x, int32_t y)
1048 {
1049 for (int32_t i = 0; i <= 1; ++i)
1050 {
1051 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1052 {
1053 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1054 }
1055 else
1056 {
1057 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1058 }
1059 }
1060 int32_t b=1;
1061
1062 if(x&8) b<<=2;
1063
1064 if(y&8) b<<=1;
1065 newcombo const& cmb = combobuf[FFORCOMBO(x,y)];
1066 if (cmb.type == cWATER && (cmb.usrflags&cflag4) && (cmb.walk&b)) return cSHALLOWWATER;
1067 if (cmb.type == cWATER && (cmb.usrflags&cflag3) && (cmb.walk&b)) return cNONE;
1068 return cmb.type;
1069 }
1070
1071 int32_t FFORCOMBO_L(int32_t layer, int32_t x, int32_t y)
1072 {
1073 if (auto ffc_handle = getFFCAt(x, y))
1074 return ffc_handle->data();
1075
1076 return layer ? MAPCOMBOL(layer, x, y) : MAPCOMBO(x,y);
1077 }
1078
1079 int32_t FFORCOMBOTYPE_L(int32_t layer, int32_t x, int32_t y)
1080 {
1081 return combobuf[FFORCOMBO_L(layer,x,y)].type;
1082 }
1083
1084 70141128 int32_t MAPCOMBOFLAG(int32_t x,int32_t y)
1085 {
1086
2/2
✓ Branch 0 taken 27852 times.
✓ Branch 1 taken 70113276 times.
70141128 if (!is_in_world_bounds(x, y))
1087 27852 return 0;
1088
1089 70113276 mapscr* scr = get_scr_for_world_xy(x, y);
1090 70113276 int pos = COMBOPOS(x%256, y%176);
1091 70113276 return combobuf[scr->data[pos]].flag;
1092 70141128 }
1093
1094 56810322 int32_t MAPFFCOMBOFLAG(int32_t x,int32_t y)
1095 {
1096
2/2
✓ Branch 0 taken 746177 times.
✓ Branch 1 taken 56064145 times.
56810322 if (auto ffc_handle = getFFCAt(x, y))
1097 746177 return ffc_handle->cflag();
1098
1099 56064145 return 0;
1100 56810322 }
1101
1102 1313410195 std::optional<ffc_handle_t> getFFCAt(int32_t x, int32_t y)
1103 {
1104 2789213607 return find_ffc([&](const ffc_handle_t& ffc_handle) {
1105 1475803412 return ffcIsAt(ffc_handle, x, y);
1106 });
1107 }
1108
1109 3044 int32_t MAPCOMBO(const rpos_handle_t& rpos_handle)
1110 {
1111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3044 times.
3044 if (!rpos_handle.scr->is_valid()) return 0;
1112 3044 return rpos_handle.data();
1113 3044 }
1114
1115 3171344973 int32_t MAPCOMBO2(int32_t layer, int32_t x, int32_t y)
1116 {
1117 DCHECK_LAYER_NEG1_INDEX(layer);
1118
2/2
✓ Branch 0 taken 22425854 times.
✓ Branch 1 taken 3148919119 times.
3171344973 if (!is_in_world_bounds(x, y)) return 0;
1119
2/2
✓ Branch 0 taken 3079591627 times.
✓ Branch 1 taken 69327492 times.
3148919119 if (layer == -1) return MAPCOMBO(x, y);
1120
1121 3079591627 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1122
2/2
✓ Branch 0 taken 2118959205 times.
✓ Branch 1 taken 960632422 times.
3079591627 if (!rpos_handle.scr->is_valid()) return 0;
1123
1124 960632422 return rpos_handle.data();
1125 3171344973 }
1126
1127 17375392 static void _handle_screen_load_trigger(const combined_handle_t& handle)
1128 {
1129 17375392 auto cid = handle.data();
1130 17375392 auto* cmb = &handle.combo();
1131 17375392 bool done = false;
1132 17375392 std::set<int32_t> visited;
1133
2/2
✓ Branch 0 taken 17375392 times.
✓ Branch 1 taken 17375392 times.
34750784 while(!done)
1134 {
1135
2/4
✓ Branch 0 taken 17375392 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17375392 times.
17375392 if(visited.contains(cid))
1136 {
1137 Z_error("Combo '%d' was part of an infinite trigger loop, breaking out of loop", cid);
1138 break; // prevent infinite loop
1139 }
1140
1/2
✓ Branch 0 taken 17375392 times.
✗ Branch 1 not taken.
17375392 visited.insert(cid);
1141
1142 17375392 done = true; // don't loop again unless something changes
1143
2/2
✓ Branch 0 taken 17375392 times.
✓ Branch 1 taken 593255 times.
17968647 for(size_t idx = 0; idx < cmb->triggers.size(); ++idx)
1144 {
1145 593255 auto& trig = cmb->triggers[idx];
1146
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 593232 times.
593255 if (trig.triggerflags[4] & combotriggerSCREENLOAD)
1147
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 do_trigger_combo(handle, idx);
1148 593232 else continue; // can skip checking handle.data()
1149
1150
2/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
23 if(handle.data() != cid)
1151 {
1152 cid = handle.data();
1153 cmb = &handle.combo();
1154 done = false; // loop again for the new combo
1155 break;
1156 }
1157 23 }
1158 }
1159 17375392 }
1160 51764 static void handle_screen_load_trigger(const screen_handles_t& screen_handles)
1161 {
1162 51764 for_every_combo_in_screen(screen_handles, _handle_screen_load_trigger);
1163 51764 }
1164 34820 void handle_region_load_trigger()
1165 {
1166
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 34668 times.
34820 if (is_in_scrolling_region())
1167 {
1168
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 19456 times.
19608 for (int screen = 0; screen < 128; screen++)
1169 {
1170
2/2
✓ Branch 0 taken 18156 times.
✓ Branch 1 taken 1300 times.
19456 if (is_in_current_region(screen))
1171 1300 handle_screen_load_trigger(create_screen_handles_one(get_scr(screen)));
1172 19456 }
1173 152 }
1174 34668 else handle_screen_load_trigger(create_screen_handles_one(get_scr(hero_screen)));
1175 34820 }
1176
1177 15796 static void apply_state_changes_to_screen(mapscr& scr, int32_t map, int32_t screen, int32_t flags, bool secrets_do_replay_comment)
1178 {
1179 15796 auto screen_handles = create_screen_handles_one(&scr);
1180
1181
3/4
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 15261 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 535 times.
15796 if ((flags & mSECRET) && canPermSecret(cur_dmap, screen))
1182 {
1183 535 reveal_hidden_stairs(&scr, screen, false);
1184 535 bool do_layers = false;
1185 535 bool from_active_screen = false;
1186 535 trigger_secrets_for_screen_internal(screen_handles, do_layers, from_active_screen, -3, secrets_do_replay_comment);
1187 535 }
1188
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if (flags & mLIGHTBEAM)
1189 {
1190 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
1191 if (rpos_handle.ctype() == cLIGHTTARGET)
1192 {
1193 if (!(rpos_handle.combo().usrflags&cflag1)) //Unlit version
1194 rpos_handle.increment_data();
1195 }
1196 });
1197 }
1198
1199 15796 int lvl = DMaps[cur_dmap].level;
1200 15796 toggle_switches(game->lvlswitches[lvl], true, screen_handles);
1201 15796 toggle_gswitches_load(screen_handles);
1202
1203
2/2
✓ Branch 0 taken 15704 times.
✓ Branch 1 taken 92 times.
15796 if(flags&mLOCKBLOCK) // if special stuff done before
1204 {
1205 92 remove_screenstatecombos2(screen_handles, false, cLOCKBLOCK, cLOCKBLOCK2);
1206 92 }
1207
1208
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mBOSSLOCKBLOCK) // if special stuff done before
1209 {
1210 remove_screenstatecombos2(screen_handles, false, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
1211 }
1212
1213
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mCHEST) // if special stuff done before
1214 {
1215 remove_screenstatecombos2(screen_handles, false, cCHEST, cCHEST2);
1216 }
1217
1218
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mCHEST) // if special stuff done before
1219 {
1220 remove_screenstatecombos2(screen_handles, false, cLOCKEDCHEST, cLOCKEDCHEST2);
1221 }
1222
1223
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mBOSSCHEST) // if special stuff done before
1224 {
1225 remove_screenstatecombos2(screen_handles, false, cBOSSCHEST, cBOSSCHEST2);
1226 }
1227
1228
1229 15796 int mi = mapind(map, screen);
1230 15796 clear_xdoors_mi(screen_handles, mi);
1231 15796 clear_xstatecombos_mi(screen_handles, mi);
1232
1233 15796 handle_screen_load_trigger(screen_handles);
1234 15796 }
1235
1236 53166 std::optional<mapscr> load_temp_mapscr_and_apply_secrets(int32_t map, int32_t screen, int32_t layer, bool secrets, bool secrets_do_replay_comment)
1237 {
1238
2/4
✓ Branch 0 taken 53166 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53166 times.
53166 if (map < 0 || screen < 0)
1239 return std::nullopt;
1240
1241 53166 const mapscr* source = get_canonical_scr(map, screen);
1242
2/2
✓ Branch 0 taken 40953 times.
✓ Branch 1 taken 12213 times.
53166 if (!source->is_valid())
1243 12213 return std::nullopt;
1244
1245
2/2
✓ Branch 0 taken 8307 times.
✓ Branch 1 taken 32646 times.
40953 if (layer >= 0)
1246 {
1247
2/2
✓ Branch 0 taken 25157 times.
✓ Branch 1 taken 7489 times.
32646 if (source->layermap[layer] <= 0)
1248 25157 return std::nullopt;
1249
1250 7489 source = get_canonical_scr(source->layermap[layer] - 1, source->layerscreen[layer]);
1251
1/2
✓ Branch 0 taken 7489 times.
✗ Branch 1 not taken.
7489 if (!source->is_valid())
1252 return std::nullopt;
1253 7489 }
1254
1255
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 int flags = secrets ? game->maps[mapind(map, screen)] : 0;
1256 15796 mapscr scr = *source;
1257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15796 times.
15796 apply_state_changes_to_screen(scr, map, screen, flags, secrets_do_replay_comment);
1258
1259 15796 return scr;
1260 53166 }
1261
1262 27203 static int32_t MAPCOMBO3_impl(int32_t map, int32_t screen, int32_t layer, int32_t pos, bool secrets)
1263 {
1264
2/4
✓ Branch 0 taken 27203 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27203 times.
27203 if (map < 0 || screen < 0) return 0;
1265
1266
2/4
✓ Branch 0 taken 27203 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27203 times.
27203 if(pos>175 || pos < 0)
1267 return 0;
1268
1269 // TODO: consider caching this (invalidate on any modification via scripting, or anything
1270 // `apply_state_changes_to_screen` checks).
1271
4/5
✓ Branch 0 taken 4976 times.
✓ Branch 1 taken 22227 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4976 times.
✓ Branch 4 taken 22227 times.
32179 if (auto s = load_temp_mapscr_and_apply_secrets(map, screen, layer, secrets))
1272 4976 return s->data[pos];
1273
1274 22227 return 0;
1275 27203 }
1276
1277 // Read from the current temporary screens or, if (map, screen) is not loaded,
1278 // load that screen and apply the relevant secrets before evaluating the combo at that position.
1279 138733544 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets)
1280 {
1281 DCHECK_LAYER_NEG1_INDEX(layer);
1282 DCHECK(map >= 0 && screen >= 0);
1283
1284
2/2
✓ Branch 0 taken 138706341 times.
✓ Branch 1 taken 27203 times.
138733544 if (is_in_current_region(map, screen)) return MAPCOMBO2(layer, x, y);
1285
1286 // Screen is not in the current region, so we have to load and trigger some secrets.
1287 27203 int pos = COMBOPOS(x, y);
1288 27203 return MAPCOMBO3_impl(map, screen, layer, pos, secrets);
1289 138733544 }
1290
1291 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, rpos_t rpos, bool secrets)
1292 {
1293 DCHECK_LAYER_NEG1_INDEX(layer);
1294 DCHECK(map >= 0 && screen >= 0);
1295 DCHECK(is_valid_rpos(rpos));
1296
1297 if (is_in_current_region(map, screen)) return MAPCOMBO(get_rpos_handle(rpos, layer + 1));
1298
1299 // Screen is not currently loaded, so we have to load and trigger some secrets.
1300 return MAPCOMBO3_impl(map, screen, layer, RPOS_TO_POS(rpos), secrets);
1301 }
1302
1303 int32_t MAPCSET2(int32_t layer,int32_t x,int32_t y)
1304 {
1305 DCHECK_LAYER_NEG1_INDEX(layer);
1306 if (!is_in_world_bounds(x, y))
1307 return 0;
1308 if (layer == -1) return MAPCSET(x, y);
1309
1310 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1311 if (!rpos_handle.scr->is_valid()) return 0;
1312
1313 return rpos_handle.cset();
1314 }
1315
1316 98864822 int32_t MAPFLAG2(int32_t layer,int32_t x,int32_t y)
1317 {
1318 DCHECK_LAYER_NEG1_INDEX(layer);
1319
3/4
✓ Branch 0 taken 1902026 times.
✓ Branch 1 taken 96962796 times.
✓ Branch 2 taken 1902026 times.
✗ Branch 3 not taken.
98864822 if (!get_qr(qr_BUGGED_LAYERED_FLAGS) && (!is_in_world_bounds(x, y)))
1320 return 0;
1321
2/2
✓ Branch 0 taken 81262429 times.
✓ Branch 1 taken 17602393 times.
98864822 if (layer == -1) return MAPFLAG(x, y);
1322
1323 81262429 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1324
2/2
✓ Branch 0 taken 62947768 times.
✓ Branch 1 taken 18314661 times.
81262429 if (!rpos_handle.scr->is_valid()) return 0;
1325
1326 18314661 return rpos_handle.sflag();
1327 98864822 }
1328
1329 2518104 int32_t COMBOTYPE2(int32_t layer,int32_t x,int32_t y)
1330 {
1331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2518104 times.
2518104 if(layer < 1)
1332 {
1333
2/2
✓ Branch 0 taken 5036208 times.
✓ Branch 1 taken 2518104 times.
7554312 for (int32_t i = layer+1; i <= 1; ++i)
1334 {
1335
2/2
✓ Branch 0 taken 4212456 times.
✓ Branch 1 taken 823752 times.
5036208 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1336 {
1337
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4212456 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4212456 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1338 4212456 }
1339 else
1340 {
1341
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 823752 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
823752 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1342 }
1343 5036208 }
1344 2518104 }
1345
1/2
✓ Branch 0 taken 2518104 times.
✗ Branch 1 not taken.
2518104 if(layer==-1) return COMBOTYPE(x,y);
1346
1347 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1348 if (!rpos_handle.scr->is_valid()) return 0;
1349
1350 return rpos_handle.ctype();
1351 2518104 }
1352
1353 // Returns the flag for the combo at the given position.
1354 // This is also known as an "inherent flag".
1355 97089680 int32_t MAPCOMBOFLAG2(int32_t layer,int32_t x,int32_t y)
1356 {
1357 DCHECK_LAYER_NEG1_INDEX(layer);
1358
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 97089392 times.
97089680 if (!is_in_world_bounds(x, y))
1359 288 return 0;
1360
2/2
✓ Branch 0 taken 81199462 times.
✓ Branch 1 taken 15889930 times.
97089392 if (layer == -1) return MAPCOMBOFLAG(x, y);
1361
1362 81199462 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1363
2/2
✓ Branch 0 taken 62957681 times.
✓ Branch 1 taken 18241781 times.
81199462 if (!rpos_handle.scr->is_valid()) return 0;
1364
1365 18241781 return rpos_handle.cflag();
1366 97089680 }
1367
1368 11802059 bool HASFLAG(int32_t flag, int32_t layer, rpos_t rpos)
1369 {
1370 DCHECK_LAYER_ZERO_INDEX(layer);
1371 11802059 auto rpos_handle = get_rpos_handle(rpos, layer);
1372
2/2
✓ Branch 0 taken 6511420 times.
✓ Branch 1 taken 5290639 times.
11802059 if (!rpos_handle.scr->is_valid()) return false;
1373
2/2
✓ Branch 0 taken 4565 times.
✓ Branch 1 taken 5286074 times.
5290639 if (rpos_handle.sflag() == flag) return true;
1374
2/2
✓ Branch 0 taken 37705 times.
✓ Branch 1 taken 5248369 times.
5286074 if (rpos_handle.cflag() == flag) return true;
1375 5248369 return false;
1376 11802059 }
1377
1378 1722093 bool HASFLAG_ANY(int32_t flag, rpos_t rpos)
1379 {
1380 DCHECK(is_valid_rpos(rpos));
1381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1722093 times.
1722093 if (rpos > region_max_rpos) return false;
1382
1383
2/2
✓ Branch 0 taken 11802059 times.
✓ Branch 1 taken 1679823 times.
13481882 for(auto q = 0; q < 7; ++q)
1384 {
1385
2/2
✓ Branch 0 taken 42270 times.
✓ Branch 1 taken 11759789 times.
11802059 if(HASFLAG(flag, q, rpos))
1386 42270 return true;
1387 11759789 }
1388 1679823 return false;
1389 1722093 }
1390
1391 const char *screenstate_string[16] =
1392 {
1393 "Door Up", "Door Down", "Door Left", "Door Right", "Item", "Special Item", "No Return",
1394 "Temporary No Return", "Lock Blocks", "Boss Lock Blocks", "Chests", "Locked Chests",
1395 "Boss Locked Chests", "Secrets", "Visited", "Light Beams"
1396 };
1397
1398 34866 void eventlog_mapflags()
1399 {
1400 34866 std::ostringstream oss;
1401
1402 34866 int mi = mapind(cur_map, home_screen);
1403
1/2
✓ Branch 0 taken 34866 times.
✗ Branch 1 not taken.
34866 word g = game->maps[mi] &0x3FFF;
1404
1405
2/4
✓ Branch 0 taken 34866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34866 times.
✗ Branch 3 not taken.
34866 oss << fmt::format("Screen ({}, {:02X})", cur_map+1, home_screen);
1406
2/2
✓ Branch 0 taken 7055 times.
✓ Branch 1 taken 27811 times.
34866 if(g) // Main States
1407 {
1408 static const int order[] =
1409 {
1410 mSECRET, mITEM, mSPECIALITEM, mLOCKBLOCK, mBOSSLOCKBLOCK,
1411 mCHEST, mLOCKEDCHEST, mBOSSCHEST,
1412 mDOOR_UP, mDOOR_DOWN, mDOOR_LEFT, mDOOR_RIGHT,
1413 mNEVERRET, mTMPNORET
1414 };
1415
1416
1/2
✓ Branch 0 taken 7055 times.
✗ Branch 1 not taken.
7055 oss << " [";
1417 7055 bool comma = false;
1418
2/2
✓ Branch 0 taken 7055 times.
✓ Branch 1 taken 98770 times.
105825 for(int fl : order)
1419 {
1420
2/2
✓ Branch 0 taken 8973 times.
✓ Branch 1 taken 89797 times.
98770 if(!(g&fl))
1421 89797 continue;
1422 8973 byte ind = byte(log2(double(fl)));
1423
2/2
✓ Branch 0 taken 1918 times.
✓ Branch 1 taken 7055 times.
8973 if(comma)
1424
1/2
✓ Branch 0 taken 1918 times.
✗ Branch 1 not taken.
1918 oss << ", ";
1425
1/2
✓ Branch 0 taken 8973 times.
✗ Branch 1 not taken.
8973 oss << screenstate_string[ind];
1426 8973 comma = true;
1427 }
1428
1/2
✓ Branch 0 taken 7055 times.
✗ Branch 1 not taken.
7055 oss << "]";
1429 7055 }
1430
3/4
✓ Branch 0 taken 34866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 34828 times.
34866 if(game->xstates[mi]) // ExStates
1431 {
1432
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 oss << " Ex[";
1433 38 bool comma = false;
1434
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 1216 times.
1254 for(byte fl = 0; fl < 32; ++fl)
1435 {
1436
3/4
✓ Branch 0 taken 1216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✓ Branch 3 taken 1170 times.
1216 if(game->xstates[mi] & (1<<fl))
1437 {
1438
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 38 times.
46 if(comma)
1439
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 oss << ", ";
1440
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 oss << int(fl);
1441 46 comma = true;
1442 46 }
1443 1216 }
1444
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 oss << "]";
1445 38 }
1446 { // ExDoors
1447
2/2
✓ Branch 0 taken 34866 times.
✓ Branch 1 taken 139464 times.
174330 for(int q = 0; q < 4; ++q)
1448 {
1449 139464 bool comma = false;
1450
2/4
✓ Branch 0 taken 139464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139464 times.
✗ Branch 3 not taken.
139464 if(auto v = game->xdoors[mi][q])
1451 {
1452 if(comma)
1453 oss << ",";
1454 else oss << " ExDoor";
1455 oss << "[" << dirstr[q];
1456 for(int fl = 0; fl < 8; ++fl)
1457 if(v & (1<<fl))
1458 oss << " " << int(fl);
1459 oss << "]";
1460 comma = true;
1461 }
1462 139464 }
1463 }
1464
2/4
✓ Branch 0 taken 34866 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34866 times.
34866 Z_eventlog("%s\n", oss.str().c_str());
1465 34866 }
1466
1467 // set specific flag
1468 5609 void setmapflag(mapscr* scr, int32_t flag)
1469 {
1470
2/2
✓ Branch 0 taken 5596 times.
✓ Branch 1 taken 13 times.
5609 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1471 5609 int mi = mapind(cur_map, scr->screen);
1472 5609 setmapflag_mi(scr, mi, flag);
1473 5609 }
1474 57 void setmapflag_homescr(int32_t flag)
1475 {
1476 57 int mi = mapind(cur_map, home_screen);
1477 57 setmapflag_mi(origin_scr, mi, flag);
1478 57 }
1479 2023 void setmapflag_mi(int32_t mi, int32_t flag)
1480 {
1481 2023 byte cscr = mi&((1<<7)-1);
1482 2023 byte cmap = (mi>>7);
1483 2023 mapscr* scr = origin_scr;
1484
2/2
✓ Branch 0 taken 834 times.
✓ Branch 1 taken 1189 times.
2023 if (is_in_current_region(cmap, cscr))
1485 1189 scr = get_scr(cmap, cscr);
1486
1487 2023 setmapflag_mi(scr, mi, flag);
1488 2023 }
1489
1490 8465 static void log_state_change(int map, int screen, std::string action)
1491 {
1492
6/6
✓ Branch 0 taken 1911 times.
✓ Branch 1 taken 6554 times.
✓ Branch 2 taken 994 times.
✓ Branch 3 taken 917 times.
✓ Branch 4 taken 352 times.
✓ Branch 5 taken 642 times.
8465 if (is_in_current_region(map, screen) || (map == cur_map && screen == home_screen))
1493 6906 Z_eventlog("[Map %d, Screen %02X (current)] %s\n", map + 1, screen, action.c_str());
1494 else
1495 1559 Z_eventlog("[Map %d, Screen %02X] %s\n", map + 1, screen, action.c_str());
1496 8465 }
1497
1498 7689 void setmapflag_mi(mapscr* scr, int32_t mi, int32_t flag)
1499 {
1500 7689 byte cscr = mi&((1<<7)-1);
1501 7689 byte cmap = (mi>>7);
1502
1503 7689 float temp=log2((float)flag);
1504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7689 times.
7689 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1505
1506
3/4
✓ Branch 0 taken 7689 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1552 times.
✓ Branch 3 taken 6137 times.
7689 if (replay_is_active() && !(game->maps[mi] & flag))
1507
1/2
✓ Branch 0 taken 6137 times.
✗ Branch 1 not taken.
6137 replay_step_comment(fmt::format("map {} scr {} flag {}", cmap, cscr, state_string));
1508 7689 game->maps[mi] |= flag;
1509
1/2
✓ Branch 0 taken 7689 times.
✗ Branch 1 not taken.
7689 log_state_change(cmap, cscr, fmt::format("State set: {}", state_string));
1510
1511
10/10
✓ Branch 0 taken 5452 times.
✓ Branch 1 taken 2237 times.
✓ Branch 2 taken 3613 times.
✓ Branch 3 taken 1839 times.
✓ Branch 4 taken 3030 times.
✓ Branch 5 taken 583 times.
✓ Branch 6 taken 2876 times.
✓ Branch 7 taken 154 times.
✓ Branch 8 taken 13 times.
✓ Branch 9 taken 2479 times.
10181 if(flag==mSECRET||flag==mITEM||flag==mSPECIALITEM||flag==mLOCKBLOCK||
1512
6/6
✓ Branch 0 taken 2829 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 2684 times.
✓ Branch 3 taken 145 times.
✓ Branch 4 taken 2492 times.
✓ Branch 5 taken 192 times.
2876 flag==mBOSSLOCKBLOCK||flag==mCHEST||flag==mBOSSCHEST||flag==mLOCKEDCHEST)
1513 {
1514 5210 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1515 5210 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1516
1517 5210 std::vector<int32_t> done;
1518
2/2
✓ Branch 0 taken 5095 times.
✓ Branch 1 taken 115 times.
5210 bool looped = (nmap==cmap+1 && nscr==cscr);
1519
1520
6/6
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 5158 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 486 times.
✓ Branch 5 taken 5210 times.
5696 while((nmap!=0) && !looped && !(nscr>=128))
1521 {
1522
5/6
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 364 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 171 times.
✓ Branch 5 taken 193 times.
486 if((scr->nocarry&flag)!=flag && !(game->maps[((nmap-1)<<7)+nscr] & flag))
1523 {
1524
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 log_state_change(nmap, nscr, "State change carried over");
1525
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 if (replay_is_active())
1526
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 replay_step_comment(fmt::format("map {} scr {} flag {} carry", nmap, nscr, state_string));
1527
1/2
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
193 game->maps[((nmap-1)<<7)+nscr] |= flag;
1528 193 }
1529
1530 486 cmap=nmap;
1531 486 cscr=nscr;
1532 486 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1533 486 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1534
1535
2/2
✓ Branch 0 taken 1480 times.
✓ Branch 1 taken 486 times.
1966 for(auto it = done.begin(); it != done.end(); it++)
1536 {
1537
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 52 times.
1480 if(*it == ((nmap-1)<<7)+nscr)
1538 52 looped = true;
1539 1480 }
1540
1541
1/2
✓ Branch 0 taken 486 times.
✗ Branch 1 not taken.
486 done.push_back(((nmap-1)<<7)+nscr);
1542 }
1543 5210 }
1544 7689 }
1545
1546 void unsetmapflag_home(int32_t flag, bool anyflag)
1547 {
1548 int mi = mapind(cur_map, home_screen);
1549 unsetmapflag_mi(origin_scr, mi, flag, anyflag);
1550 }
1551
1552 void unsetmapflag(mapscr* scr, int32_t flag, bool anyflag)
1553 {
1554 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1555 int mi = mapind(cur_map, scr->screen);
1556 unsetmapflag_mi(scr, mi, flag, anyflag);
1557 }
1558
1559 471 void unsetmapflag_mi(int32_t mi, int32_t flag, bool anyflag)
1560 {
1561 471 byte cscr = mi&((1<<7)-1);
1562 471 byte cmap = (mi>>7);
1563 471 mapscr* scr = origin_scr;
1564
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if (is_in_current_region(cmap, cscr))
1565 11 scr = get_scr(cmap, cscr);
1566
1567 471 unsetmapflag_mi(scr, mi, flag, anyflag);
1568 471 }
1569
1570 471 void unsetmapflag_mi(mapscr* scr, int32_t mi, int32_t flag, bool anyflag)
1571 {
1572 471 byte cscr = mi&((1<<7)-1);
1573 471 byte cmap = (mi>>7);
1574
1575
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if(anyflag)
1576 460 game->maps[mi] &= ~flag;
1577
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 else if(flag==mITEM || flag==mSPECIALITEM)
1578 {
1579 if(!(scr->flags4&fNOITEMRESET))
1580 game->maps[mi] &= ~flag;
1581 }
1582 11 else game->maps[mi] &= ~flag;
1583
1584 471 float temp=log2((float)flag);
1585
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1586
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 log_state_change(cmap, cscr, fmt::format("State unset: {}", state_string));
1587
1588
5/10
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
471 if(flag==mSECRET||flag==mITEM||flag==mSPECIALITEM||flag==mLOCKBLOCK||
1589
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
11 flag==mBOSSLOCKBLOCK||flag==mCHEST||flag==mBOSSCHEST||flag==mLOCKEDCHEST)
1590 {
1591 471 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1592 471 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1593
1594 471 std::vector<int32_t> done;
1595
2/2
✓ Branch 0 taken 466 times.
✓ Branch 1 taken 5 times.
471 bool looped = (nmap==cmap+1 && nscr==cscr);
1596
1597
6/6
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 465 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 84 times.
✓ Branch 5 taken 471 times.
555 while((nmap!=0) && !looped && !(nscr>=128))
1598 {
1599
4/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 72 times.
84 if((scr->nocarry&flag)!=flag && (game->maps[((nmap-1)<<7)+nscr] & flag))
1600 {
1601
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
72 log_state_change(nmap, nscr, "State change carried over");
1602
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 game->maps[((nmap-1)<<7)+nscr] &= ~flag;
1603 72 }
1604
1605 84 cmap=nmap;
1606 84 cscr=nscr;
1607 84 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1608 84 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1609
1610
2/2
✓ Branch 0 taken 546 times.
✓ Branch 1 taken 84 times.
630 for(std::vector<int32_t>::iterator it = done.begin(); it != done.end(); it++)
1611 {
1612
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 6 times.
546 if(*it == ((nmap-1)<<7)+nscr)
1613 6 looped = true;
1614 546 }
1615
1616
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 done.push_back(((nmap-1)<<7)+nscr);
1617 }
1618 471 }
1619 471 }
1620
1621 44194798 bool getmapflag(int32_t screen, int32_t flag)
1622 {
1623
2/2
✓ Branch 0 taken 1164399 times.
✓ Branch 1 taken 43030399 times.
44194798 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1624 44194798 return (game->maps[mi] & flag) != 0;
1625 }
1626 162336 bool getmapflag(mapscr* scr, int32_t flag)
1627 {
1628 162336 return getmapflag(scr->screen, flag);
1629 }
1630
1631 59 void setxmapflag(int32_t screen, uint32_t flag)
1632 {
1633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1634 59 setxmapflag_mi(mi, flag);
1635 59 }
1636 61 void setxmapflag_mi(int32_t mi, uint32_t flag)
1637 {
1638
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 40 times.
61 if(game->xstates[mi] & flag) return;
1639 40 byte cscr = mi&((1<<7)-1);
1640 40 byte cmap = (mi>>7);
1641
1642 40 byte temp=(byte)log2((double)flag);
1643
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 log_state_change(cmap, cscr, fmt::format("ExtraState set: {}", temp));
1644
1645 40 game->xstates[mi] |= flag;
1646 61 }
1647 void unsetxmapflag(int32_t screen, uint32_t flag)
1648 {
1649 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1650 unsetxmapflag_mi(mi, flag);
1651 }
1652 void unsetxmapflag_mi(int32_t mi, uint32_t flag)
1653 {
1654 if(!(game->xstates[mi] & flag)) return;
1655 byte cscr = mi&((1<<7)-1);
1656 byte cmap = (mi>>7);
1657 byte temp=(byte)log2((double)flag);
1658 log_state_change(cmap, cscr, fmt::format("ExtraState unset: {}", temp));
1659 game->xstates[mi] &= ~flag;
1660 }
1661 29 bool getxmapflag(int32_t screen, uint32_t flag)
1662 {
1663
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
29 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1664 29 return getxmapflag_mi(mi, flag);
1665 }
1666 471582539 bool getxmapflag_mi(int32_t mi, uint32_t flag)
1667 {
1668 471582539 return (game->xstates[mi] & flag) != 0;
1669 }
1670
1671 void setxdoor_mi(uint mi, uint dir, uint ind, bool state)
1672 {
1673 if(mi > game->xdoors.size() || dir > 3 || ind > 8)
1674 return;
1675 if(!(game->xdoors[mi][dir] & (1<<ind)) == !state)
1676 return;
1677
1678 SETFLAG(game->xdoors[mi][dir], 1<<ind, state);
1679
1680 int cscr = mi % MAPSCRSNORMAL;
1681 int cmap = mi / MAPSCRSNORMAL;
1682 if (state)
1683 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] set", dirstr[dir], ind));
1684 else
1685 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] unset", dirstr[dir], ind));
1686 }
1687 471582496 bool getxdoor_mi(uint mi, uint dir, uint ind)
1688 {
1689
3/6
✓ Branch 0 taken 471582496 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 471582496 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 471582496 times.
471582496 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1690 return false;
1691 471582496 return (game->xdoors[mi][dir] & (1<<ind));
1692 471582496 }
1693 bool getxdoor(int32_t screen, uint dir, uint ind)
1694 {
1695 int mi = mapind(cur_map, screen);
1696 return getxdoor_mi(mi,dir,ind);
1697 }
1698
1699 401 void set_doorstate_mi(uint mi, uint dir)
1700 {
1701
1/2
✓ Branch 0 taken 401 times.
✗ Branch 1 not taken.
401 if(dir >= 4)
1702 return;
1703 401 setmapflag_mi(mi, mDOOR_UP << dir);
1704
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 400 times.
401 if(auto di = nextscr_mi(mi, dir))
1705 400 setmapflag_mi(*di, mDOOR_UP << oppositeDir[dir]);
1706 401 }
1707 401 void set_doorstate(uint screen, uint dir)
1708 {
1709 401 int mi = mapind(cur_map, screen);
1710 401 set_doorstate_mi(mi, dir);
1711 401 }
1712
1713 void set_xdoorstate_mi(uint mi, uint dir, uint ind, bool state)
1714 {
1715 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1716 return;
1717 setxdoor_mi(mi, dir, ind, state);
1718 if(auto di = nextscr_mi(mi, dir))
1719 setxdoor_mi(*di, oppositeDir[dir], ind, state);
1720 }
1721
1722 void set_xdoorstate(int32_t screen,uint dir, uint ind, bool state)
1723 {
1724 int mi = mapind(cur_map, screen);
1725 set_xdoorstate_mi(mi, dir, ind, state);
1726 }
1727
1728 57 int32_t WARPCODE(int32_t dmap,int32_t screen,int32_t dw)
1729 // returns: -1 = not a warp screen
1730 // 0+ = warp screen code ( high byte=dmap, low byte=scr )
1731 {
1732 57 const mapscr *scr = get_canonical_scr(DMaps[dmap].map, screen);
1733
1734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(scr->room!=rWARP)
1735 return -1;
1736
1737 57 int32_t ring=scr->catchall;
1738 57 int32_t size=QMisc.warp[ring].size;
1739
1740
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 if(size==0)
1741 return -2;
1742
1743 57 int32_t index=-1;
1744
1745
2/2
✓ Branch 0 taken 289 times.
✓ Branch 1 taken 57 times.
346 for(int32_t i=0; i<size; i++)
1746
6/6
✓ Branch 0 taken 230 times.
✓ Branch 1 taken 59 times.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 173 times.
✓ Branch 5 taken 57 times.
289 if(dmap==QMisc.warp[ring].dmap[i] && screen==
1747 346 (QMisc.warp[ring].scr[i] + DMaps[dmap].xoff))
1748 57 index=i;
1749
1750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(index==-1)
1751 return -3;
1752
1753 57 index = (index+dw)%size;
1754 57 return (QMisc.warp[ring].dmap[index] << 8) + QMisc.warp[ring].scr[index];
1755 57 }
1756
1757 14782683 void update_combo_cycling()
1758 {
1759 14782683 auto& combo_cache = combo_caches::can_cycle;
1760
1761 static int32_t newdata[176];
1762 static int32_t newcset[176];
1763 static bool initialized=false;
1764
1765 // Just a simple bit of optimization
1766
2/2
✓ Branch 0 taken 14782378 times.
✓ Branch 1 taken 305 times.
14782683 if(!initialized)
1767 {
1768
2/2
✓ Branch 0 taken 53680 times.
✓ Branch 1 taken 305 times.
53985 for(int32_t i=0; i<176; i++)
1769 {
1770 53680 newdata[i]=-1;
1771 53680 newcset[i]=-1;
1772 53680 }
1773
1774 305 initialized=true;
1775 305 }
1776
1777 14782683 std::set<uint16_t> restartanim;
1778
1779
1/2
✓ Branch 0 taken 14782683 times.
✗ Branch 1 not taken.
29954734 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
1780 15172051 int screen = scr->screen;
1781 int32_t x;
1782
1783
2/2
✓ Branch 0 taken 2670280976 times.
✓ Branch 1 taken 15172051 times.
2685453027 for(int32_t i=0; i<176; i++)
1784 {
1785 2670280976 x=scr->data[i];
1786 2670280976 auto& mini_cmb = combo_cache.minis[x];
1787
2/2
✓ Branch 0 taken 3273852 times.
✓ Branch 1 taken 2667007124 times.
2670280976 if (!mini_cmb.can_cycle)
1788 2667007124 continue;
1789
1790 3273852 newcombo const& cmb = combobuf[x];
1791
1792 //time to restart
1793
4/4
✓ Branch 0 taken 902678 times.
✓ Branch 1 taken 2371174 times.
✓ Branch 2 taken 474422 times.
✓ Branch 3 taken 428256 times.
3273852 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1794 {
1795 428256 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428256 times.
428256 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1797 428256 newdata[i] = c;
1798
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 428240 times.
428256 if(!(cmb.animflags & AF_CYCLENOCSET))
1799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428240 times.
428240 newcset[i] = cycle_under ? scr->undercset : cmb.nextcset;
1800
1801
2/2
✓ Branch 0 taken 427212 times.
✓ Branch 1 taken 1044 times.
428256 if(combobuf[c].animflags & AF_CYCLE)
1802 {
1803 1044 restartanim.insert(c);
1804 1044 }
1805 428256 }
1806 3273852 }
1807
1808 15172051 int rpos_base = (int)POS_TO_RPOS(0, region_scr_x, region_scr_y);
1809
2/2
✓ Branch 0 taken 2670280976 times.
✓ Branch 1 taken 15172051 times.
2685453027 for(int32_t i=0; i<176; i++)
1810 {
1811
2/2
✓ Branch 0 taken 428256 times.
✓ Branch 1 taken 2669852720 times.
2670280976 if(newdata[i]==-1)
1812 2669852720 continue;
1813
1814 428256 rpos_t rpos = (rpos_t)(rpos_base + i);
1815 428256 rpos_handle_t rpos_handle = {scr, screen, 0, rpos, i};
1816 428256 screen_combo_modify_preroutine(rpos_handle);
1817 428256 scr->data[i]=newdata[i];
1818
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 428240 times.
428256 if(newcset[i]>-1)
1819 428240 scr->cset[i]=newcset[i];
1820 428256 screen_combo_modify_postroutine(rpos_handle);
1821
1822 428256 newdata[i]=-1;
1823 428256 newcset[i]=-1;
1824 428256 }
1825
1826 15172051 word c = scr->numFFC();
1827
2/2
✓ Branch 0 taken 15172051 times.
✓ Branch 1 taken 453575331 times.
468747382 for(word i=0; i<c; i++)
1828 {
1829 453575331 ffcdata& ffc = scr->ffcs[i];
1830 453575331 auto& mini_cmb = combo_cache.minis[ffc.data];
1831
2/2
✓ Branch 0 taken 4173 times.
✓ Branch 1 taken 453571158 times.
453575331 if (!mini_cmb.can_cycle)
1832 453571158 continue;
1833
1834 4173 newcombo const& cmb = combobuf[ffc.data];
1835
1836 //time to restart
1837
4/4
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 3562 times.
✓ Branch 2 taken 503 times.
✓ Branch 3 taken 108 times.
4173 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1838 {
1839 108 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1841 108 zc_ffc_set(ffc, c);
1842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!(cmb.animflags & AF_CYCLENOCSET))
1843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 ffc.cset = cycle_under ? scr->undercset : cmb.nextcset;
1844
1845
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 60 times.
108 if(combobuf[ffc.data].animflags & AF_CYCLE)
1846 {
1847 60 restartanim.insert(ffc.data);
1848 60 }
1849 108 }
1850 4173 }
1851
1852
2/2
✓ Branch 0 taken 8416372 times.
✓ Branch 1 taken 6755679 times.
15172051 if(get_qr(qr_CMBCYCLELAYERS))
1853 {
1854
2/2
✓ Branch 0 taken 40534074 times.
✓ Branch 1 taken 6755679 times.
47289753 for(int32_t j=1; j<=6; j++)
1855 {
1856 40534074 mapscr* layer_scr = get_scr_layer_valid(screen, j);
1857
2/2
✓ Branch 0 taken 10909424 times.
✓ Branch 1 taken 29624650 times.
40534074 if (!layer_scr)
1858 29624650 continue;
1859
1860
2/2
✓ Branch 0 taken 1920058624 times.
✓ Branch 1 taken 10909424 times.
1930968048 for(int32_t i=0; i<176; i++)
1861 {
1862 1920058624 x=layer_scr->data[i];
1863 1920058624 auto& mini_cmb = combo_cache.minis[x];
1864
2/2
✓ Branch 0 taken 2229533 times.
✓ Branch 1 taken 1917829091 times.
1920058624 if (!mini_cmb.can_cycle)
1865 1917829091 continue;
1866
1867 2229533 newcombo const& cmb = combobuf[x];
1868
1869 //time to restart
1870
4/4
✓ Branch 0 taken 48299 times.
✓ Branch 1 taken 2181234 times.
✓ Branch 2 taken 37405 times.
✓ Branch 3 taken 10894 times.
2229533 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1871 {
1872 10894 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10894 times.
10894 auto c = cycle_under ? layer_scr->undercombo : cmb.nextcombo;
1874 10894 newdata[i] = c;
1875
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 10864 times.
10894 if(!(cmb.animflags & AF_CYCLENOCSET))
1876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10864 times.
10864 newcset[i] = cycle_under ? layer_scr->undercset : cmb.nextcset;
1877 30 else newcset[i] = layer_scr->cset[i];
1878
1879
2/2
✓ Branch 0 taken 919 times.
✓ Branch 1 taken 9975 times.
10894 if(combobuf[c].animflags & AF_CYCLE)
1880 {
1881 9975 restartanim.insert(c);
1882 9975 }
1883 10894 }
1884 2229533 }
1885
1886
2/2
✓ Branch 0 taken 1920058624 times.
✓ Branch 1 taken 10909424 times.
1930968048 for (int32_t i=0; i<176; i++)
1887 {
1888
2/2
✓ Branch 0 taken 1920047730 times.
✓ Branch 1 taken 10894 times.
1920058624 if(newdata[i]!=-1)
1889 {
1890 10894 layer_scr->data[i]=newdata[i];
1891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10894 times.
10894 if(newcset[i]>-1)
1892 10894 layer_scr->cset[i]=newcset[i];
1893 10894 newdata[i]=-1;
1894 10894 newcset[i]=-1;
1895 10894 }
1896 1920058624 }
1897 10909424 }
1898 6755679 }
1899 15172051 });
1900
1901
2/2
✓ Branch 0 taken 14782683 times.
✓ Branch 1 taken 2657 times.
14785340 for (auto i : restartanim)
1902 {
1903 2657 combobuf[i].tile = combobuf[i].o_tile;
1904 2657 combobuf[i].cur_frame=0;
1905 2657 combobuf[i].aclk = 0;
1906
1/2
✓ Branch 0 taken 2657 times.
✗ Branch 1 not taken.
2657 combo_caches::drawing.refresh(i);
1907 }
1908 14782683 }
1909
1910 1211903332 bool iswater_type(int32_t type)
1911 {
1912 // return type==cOLD_WATER || type==cSWIMWARP || type==cDIVEWARP || type==cDIVEWARPB || type==cDIVEWARPC || type==cDIVEWARPD || type==cSWIMWARPB || type==cSWIMWARPC || type==cSWIMWARPD;
1913 1211903332 return (combo_class_buf[type].water!=0);
1914 }
1915
1916 bool iswater(int32_t combo)
1917 {
1918 return iswater_type(combobuf[combo].type) && !DRIEDLAKE;
1919 }
1920 1135408 int32_t iswaterexzq(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck)
1921 {
1922 1135408 return iswaterex(combo, map, screen, layer, x, y, secrets, fullcheck, LayerCheck);
1923 }
1924
1925 // (x, y) are world coordinates
1926 58853057 int32_t iswaterex_z3(int32_t combo, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
1927 {
1928
8/8
✓ Branch 0 taken 58806878 times.
✓ Branch 1 taken 46179 times.
✓ Branch 2 taken 58766528 times.
✓ Branch 3 taken 40350 times.
✓ Branch 4 taken 58699796 times.
✓ Branch 5 taken 66732 times.
✓ Branch 6 taken 59561 times.
✓ Branch 7 taken 58640235 times.
58853057 if (x<0 || x>=world_w || y<0 || y>=world_h)
1929 212822 return false;
1930
1931 58640235 return iswaterex(combo, cur_map, cur_screen, layer, x, y, secrets, fullcheck, LayerCheck, ShallowCheck, hero, out_handle);
1932 58853057 }
1933
1934 97644803 int32_t iswaterex(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
1935 {
1936 DCHECK_LAYER_NEG1_INDEX(layer);
1937 //Honestly, fullcheck is kinda useless... I made this function back when I thought it was checking the entire combo and not just a glorified x/y value.
1938 //Fullcheck makes no sense to ever be on, but hey I guess it's here in case you ever need it...
1939
1940 //Oh hey, Zoras might actually need it. Nevermind, this had a use!
1941
2/2
✓ Branch 0 taken 57797223 times.
✓ Branch 1 taken 39847580 times.
97644803 if (get_qr(qr_SMARTER_WATER))
1942 {
1943
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 57797223 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
57797223 if (DRIEDLAKE) return 0;
1944
5/6
✓ Branch 0 taken 19670512 times.
✓ Branch 1 taken 38126711 times.
✓ Branch 2 taken 6518562 times.
✓ Branch 3 taken 13151950 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6518562 times.
57797223 if (LayerCheck && (get_qr(qr_WATER_ON_LAYER_1) || get_qr(qr_WATER_ON_LAYER_2))) //LayerCheck is a bit dumber, but it lets me add this QR without having to replace all calls, again.
1945 {
1946
2/2
✓ Branch 0 taken 38109190 times.
✓ Branch 1 taken 12478620 times.
50587810 for (int32_t m = layer; m <= 1; m++)
1947 {
1948
5/6
✓ Branch 0 taken 24957240 times.
✓ Branch 1 taken 13151950 times.
✓ Branch 2 taken 12478620 times.
✓ Branch 3 taken 12478620 times.
✓ Branch 4 taken 12478620 times.
✗ Branch 5 not taken.
50587810 if (m < 0 || m == 0 && get_qr(qr_WATER_ON_LAYER_1)
1949
1/2
✓ Branch 0 taken 12478620 times.
✗ Branch 1 not taken.
24957240 || m == 1 && get_qr(qr_WATER_ON_LAYER_2))
1950 {
1951 38109190 int32_t checkwater = iswaterex(combo, map, screen, m, x, y, secrets, fullcheck, false, ShallowCheck);
1952
2/2
✓ Branch 0 taken 37435860 times.
✓ Branch 1 taken 673330 times.
38109190 if (checkwater > 0)
1953 {
1954
2/2
✓ Branch 0 taken 673272 times.
✓ Branch 1 taken 58 times.
673330 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, m+1);
1955 673330 return checkwater;
1956 }
1957 37435860 }
1958 37435860 }
1959 12478620 return 0;
1960 }
1961 else
1962 {
1963
2/2
✓ Branch 0 taken 44659946 times.
✓ Branch 1 taken 42474511 times.
87134457 for(int32_t i=(fullcheck?3:0); i>=0; i--)
1964 {
1965 44659946 int32_t tx2=((i&2)<<2)+x;
1966 44659946 int32_t ty2=((i&1)<<3)+y;
1967 44659946 int32_t b = i; //Originally b was not needed and I read off i, but then I added the boolean for fullcheck.
1968 //In which case it's just easier to change b if fullcheck is false instead of changing i and potentially screwing up the for loop.
1969
2/2
✓ Branch 0 taken 21673 times.
✓ Branch 1 taken 44638273 times.
44659946 if (!fullcheck)
1970 {
1971 44638273 tx2 = x;
1972 44638273 ty2 = y;
1973
2/2
✓ Branch 0 taken 25106791 times.
✓ Branch 1 taken 19531482 times.
44638273 if(tx2&8) b+=2;
1974
2/2
✓ Branch 0 taken 20743068 times.
✓ Branch 1 taken 23895205 times.
44638273 if(ty2&8) b+=1;
1975 44638273 }
1976
2/2
✓ Branch 0 taken 95437520 times.
✓ Branch 1 taken 43819105 times.
139256625 for (int32_t m = layer; m <= 1; m++)
1977 {
1978 95437520 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2, true)];
1979
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 77701793 times.
95437520 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1980 {
1981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17735727 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17735727 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<b)))
1982 {
1983 return 0;
1984 }
1985 17735727 }
1986 else
1987 {
1988
4/4
✓ Branch 0 taken 175293 times.
✓ Branch 1 taken 77526500 times.
✓ Branch 2 taken 51152 times.
✓ Branch 3 taken 124141 times.
77701793 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<b)))
1989 {
1990 124141 return 0;
1991 }
1992 }
1993
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 77577652 times.
95313379 if (get_qr(qr_NO_SOLID_SWIM))
1994 {
1995
8/14
✓ Branch 0 taken 51152 times.
✓ Branch 1 taken 77526500 times.
✓ Branch 2 taken 51152 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716700 times.
✓ Branch 5 taken 76809800 times.
✓ Branch 6 taken 3461 times.
✓ Branch 7 taken 713239 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3461 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
77577652 if ((cmb.type != cBRIDGE || (!get_qr(qr_OLD_BRIDGE_COMBOS) && !(cmb.walk&(0x10<<b)))) && (cmb.walk&(1<<b)) && !((cmb.usrflags&cflag4) && cmb.type == cWATER && (cmb.walk&(0x10<<b)) && ShallowCheck))
1996 {
1997 716700 return 0;
1998 }
1999 76860952 }
2000
3/6
✓ Branch 0 taken 320336 times.
✓ Branch 1 taken 94276343 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 320336 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
94596679 if (iswater_type(cmb.type) && (cmb.walk&(1<<b)) && ((cmb.usrflags&cflag3) || (cmb.usrflags&cflag4)
2001 || (hero && current_item(itype_flippers) < cmb.attribytes[0])
2002 || (hero && ((cmb.usrflags&cflag1) && !(itemsbuf[current_item_id(itype_flippers)].flags & item_flag3)))))
2003 {
2004 if (!(ShallowCheck && (cmb.walk&(1<<b)) && (cmb.usrflags&cflag4))) return 0;
2005 }
2006 94596679 }
2007
2008 131685671 auto found_ffc_not_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2009
2/2
✓ Branch 0 taken 87338701 times.
✓ Branch 1 taken 527865 times.
87866566 if (ffcIsAt(ffc_handle, tx2, ty2))
2010 {
2011 527865 auto ty = ffc_handle.ctype();
2012
4/6
✓ Branch 0 taken 527865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144225 times.
✓ Branch 3 taken 383640 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 144225 times.
527865 if(!combo_class_buf[ty].water && !(ShallowCheck && ty == cSHALLOWWATER))
2013 527865 return true;
2014 }
2015
2016 87338701 return false;
2017 87866566 });
2018
2/2
✓ Branch 0 taken 43291240 times.
✓ Branch 1 taken 527865 times.
43819105 if (found_ffc_not_water) return 0;
2019
2020
2/2
✓ Branch 0 taken 14673 times.
✓ Branch 1 taken 43276567 times.
43291240 if(!i)
2021 {
2022 128291347 auto found_ffc_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2023
1/2
✓ Branch 0 taken 85014780 times.
✗ Branch 1 not taken.
85014780 if (ffcIsAt(ffc_handle, tx2, ty2))
2024 {
2025 auto ty = ffc_handle.ctype();
2026 if(combo_class_buf[ty].water || (ShallowCheck && ty == cSHALLOWWATER))
2027 return true;
2028 }
2029
2030 85014780 return false;
2031 85014780 });
2032
1/2
✓ Branch 0 taken 43276567 times.
✗ Branch 1 not taken.
43276567 if (found_ffc_water)
2033 {
2034 if(out_handle) *out_handle = *found_ffc_water;
2035 return found_ffc_water->data();
2036 }
2037 43276567 }
2038
2039 43291240 int32_t checkcombo = MAPCOMBO3(map, screen, layer, tx2, ty2, secrets);
2040
2/2
✓ Branch 0 taken 43246746 times.
✓ Branch 1 taken 44494 times.
43291240 if (!(combobuf[checkcombo].walk&(1<<(b+4)))) return 0;
2041
7/12
✓ Branch 0 taken 42966141 times.
✓ Branch 1 taken 280605 times.
✓ Branch 2 taken 10884083 times.
✓ Branch 3 taken 32082058 times.
✓ Branch 4 taken 10405899 times.
✓ Branch 5 taken 478184 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 10405899 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
43246746 if (iswater_type(combobuf[checkcombo].type)||(ShallowCheck && (combobuf[checkcombo].type == cSHALLOWWATER || (iswater_type(combobuf[checkcombo].type) && (combobuf[checkcombo].walk&(1<<b)) && (combobuf[checkcombo].usrflags&cflag4)))))
2042 {
2043
2/2
✓ Branch 0 taken 1227 times.
✓ Branch 1 taken 757562 times.
758789 if (i == 0)
2044 {
2045
2/2
✓ Branch 0 taken 757553 times.
✓ Branch 1 taken 9 times.
757562 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(tx2, ty2, layer+1);
2046 757562 return checkcombo;
2047 }
2048 1227 }
2049 42489184 }
2050 42474511 return 0;
2051 }
2052 }
2053 else
2054 {
2055 39847580 int32_t b = 0;
2056
2/2
✓ Branch 0 taken 20635733 times.
✓ Branch 1 taken 19211847 times.
39847580 if(x&8) b+=2;
2057
2/2
✓ Branch 0 taken 15455783 times.
✓ Branch 1 taken 24391797 times.
39847580 if(y&8) b+=1;
2058
1/2
✓ Branch 0 taken 39847580 times.
✗ Branch 1 not taken.
39847580 if (get_qr(qr_NO_SOLID_SWIM))
2059 {
2060 if (combobuf[combo].walk&(1<<b))
2061 {
2062 return 0;
2063 }
2064 }
2065
1/2
✓ Branch 0 taken 39847580 times.
✗ Branch 1 not taken.
39847580 if (!(combobuf[combo].walk&(1<<(b+4)))) return 0;
2066
8/8
✓ Branch 0 taken 38148948 times.
✓ Branch 1 taken 1698632 times.
✓ Branch 2 taken 167945 times.
✓ Branch 3 taken 37981003 times.
✓ Branch 4 taken 2129 times.
✓ Branch 5 taken 1782338 times.
✓ Branch 6 taken 163774 times.
✓ Branch 7 taken 161691 times.
39847580 if((iswater_type(combobuf[combo].type) || (ShallowCheck && combobuf[combo].type == cSHALLOWWATER)) && !DRIEDLAKE)
2067 {
2068
2/2
✓ Branch 0 taken 1943999 times.
✓ Branch 1 taken 30 times.
1944029 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, 0); //NOTE: This is only correct assuming 'combo' is 'MAPCOMBO(x,y)'
2069 1944029 return combo;
2070 }
2071 38144777 return 0;
2072 }
2073 97886029 }
2074
2075 326 bool isdamage_type(int32_t type)
2076 {
2077
1/2
✓ Branch 0 taken 326 times.
✗ Branch 1 not taken.
326 switch(type)
2078 {
2079 case cDAMAGE1: case cDAMAGE2: case cDAMAGE3: case cDAMAGE4:
2080 case cDAMAGE5: case cDAMAGE6: case cDAMAGE7:
2081 return true;
2082 }
2083 326 return false;
2084 326 }
2085
2086 2570157428 bool ispitfall_type(int32_t type)
2087 {
2088 2570157428 return combo_class_buf[type].pit != 0;
2089 }
2090
2091 2570157428 bool ispitfall(int32_t combo)
2092 {
2093 2570157428 return ispitfall_type(combobuf[combo].type);
2094 }
2095
2096 278143006 bool ispitfall(int32_t x, int32_t y)
2097 {
2098
2/2
✓ Branch 0 taken 1456039 times.
✓ Branch 1 taken 276686967 times.
278143006 if(int32_t c = MAPFFCOMBO(x,y))
2099 {
2100 1456039 return ispitfall(c) ? true : false;
2101 }
2102 276686967 int32_t c = MAPCOMBOL(2,x,y);
2103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 276686967 times.
276686967 if(ispitfall(c)) return true;
2104
2/2
✓ Branch 0 taken 263554795 times.
✓ Branch 1 taken 13132172 times.
276686967 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2105 {
2106
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 263554795 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
263554795 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return false;
2107 263554795 }
2108 else
2109 {
2110
3/4
✓ Branch 0 taken 1955 times.
✓ Branch 1 taken 13130217 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1955 times.
13132172 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return false;
2111 }
2112 276685012 c = MAPCOMBOL(1,x,y);
2113
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 276684988 times.
276685012 if(ispitfall(c)) return true;
2114
2115
2/2
✓ Branch 0 taken 263554795 times.
✓ Branch 1 taken 13130193 times.
276684988 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2116 {
2117
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 263554795 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
263554795 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return false;
2118 263554795 }
2119 else
2120 {
2121
4/4
✓ Branch 0 taken 13072 times.
✓ Branch 1 taken 13117121 times.
✓ Branch 2 taken 8777 times.
✓ Branch 3 taken 4295 times.
13130193 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return false;
2122 }
2123 276676211 c = MAPCOMBO(x,y);
2124
2/2
✓ Branch 0 taken 70756 times.
✓ Branch 1 taken 276605455 times.
276676211 if(ispitfall(c)) return true;
2125 276605455 return false;
2126 278143006 }
2127
2128 585790131 int32_t getpitfall(int32_t x, int32_t y) //Return the highest-layer active pit combo at the given position
2129 {
2130
2/2
✓ Branch 0 taken 9281019 times.
✓ Branch 1 taken 576509112 times.
585790131 if(int32_t c = MAPFFCOMBO(x,y))
2131 {
2132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9281019 times.
9281019 return ispitfall(c) ? c : 0;
2133 }
2134 576509112 int32_t c = MAPCOMBOL(2,x,y);
2135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 576509112 times.
576509112 if(ispitfall(c)) return c;
2136
2137
2/2
✓ Branch 0 taken 532652092 times.
✓ Branch 1 taken 43857020 times.
576509112 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2138 {
2139
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 532652092 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
532652092 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return 0;
2140 532652092 }
2141 else
2142 {
2143
3/4
✓ Branch 0 taken 25651 times.
✓ Branch 1 taken 43831369 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25651 times.
43857020 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return 0;
2144 }
2145 576483461 c = MAPCOMBOL(1,x,y);
2146
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 576483183 times.
576483461 if(ispitfall(c)) return c;
2147
2148
2/2
✓ Branch 0 taken 532652092 times.
✓ Branch 1 taken 43831091 times.
576483183 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2149 {
2150
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 532652092 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
532652092 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return 0;
2151 532652092 }
2152 else
2153 {
2154
4/4
✓ Branch 0 taken 144357 times.
✓ Branch 1 taken 43686734 times.
✓ Branch 2 taken 103729 times.
✓ Branch 3 taken 40628 times.
43831091 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return 0;
2155 }
2156 576379454 c = MAPCOMBO(x,y);
2157
2/2
✓ Branch 0 taken 176891 times.
✓ Branch 1 taken 576202563 times.
576379454 if(ispitfall(c)) return c;
2158 576202563 return 0;
2159 585790131 }
2160 51 optional<combined_handle_t> get_pitfall_handle(int32_t x, int32_t y) //Return the highest-layer active pit combo handle at the given position
2161 {
2162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(int32_t c = MAPFFCOMBO(x,y))
2163 {
2164 return ispitfall(c) ? getFFCAt(x,y) : nullopt;
2165 }
2166 51 int32_t c = MAPCOMBOL(2,x,y);
2167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 2);
2168
2169
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 45 times.
51 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2170 {
2171
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1))
2172 return nullopt;
2173 6 }
2174 else
2175 {
2176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
45 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1))
2177 return nullopt;
2178 }
2179 51 c = MAPCOMBOL(1,x,y);
2180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 1);
2181
2182
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 45 times.
51 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2183 {
2184
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0))
2185 return nullopt;
2186 6 }
2187 else
2188 {
2189
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
45 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0))
2190 return nullopt;
2191 }
2192 51 c = MAPCOMBO(x,y);
2193
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 0);
2194 return nullopt;
2195 51 }
2196 5525150 bool check_icy(newcombo const& cmb, int type)
2197 {
2198
1/2
✓ Branch 0 taken 5525150 times.
✗ Branch 1 not taken.
5525150 if(cmb.type != cICY)
2199 5525150 return false;
2200 switch(type)
2201 {
2202 case ICY_BLOCK:
2203 return cmb.usrflags&cflag1;
2204 case ICY_PLAYER:
2205 return cmb.usrflags&cflag2;
2206 }
2207 return false;
2208 5525150 }
2209 1843607 int get_icy(int x, int y, int type)
2210 {
2211 1843607 int32_t c = MAPCOMBOL(2,x,y);
2212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1843607 times.
1843607 if(check_icy(combobuf[c], type)) return c;
2213
2214 1843607 int screen = get_screen_for_world_xy(x, y);
2215
2216 1843607 mapscr* scr = get_scr_layer_valid(screen, 2);
2217
2/2
✓ Branch 0 taken 430769 times.
✓ Branch 1 taken 1412838 times.
1843607 if (scr)
2218 {
2219
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 1412322 times.
1412838 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2220 {
2221
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 516 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
516 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2222 516 }
2223 else
2224 {
2225
3/4
✓ Branch 0 taken 2015 times.
✓ Branch 1 taken 1410307 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2015 times.
1412322 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2226 }
2227 1410823 }
2228 1841592 c = MAPCOMBOL(1,x,y);
2229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1841592 times.
1841592 if(check_icy(combobuf[c], type)) return c;
2230
2231 1841592 scr = get_scr_layer_valid(screen, 1);
2232
2/2
✓ Branch 0 taken 73612 times.
✓ Branch 1 taken 1767980 times.
1841592 if (scr)
2233 {
2234
2/2
✓ Branch 0 taken 1934 times.
✓ Branch 1 taken 1766046 times.
1767980 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2235 {
2236
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1934 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1934 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2237 1934 }
2238 else
2239 {
2240
3/4
✓ Branch 0 taken 1641 times.
✓ Branch 1 taken 1764405 times.
✓ Branch 2 taken 1641 times.
✗ Branch 3 not taken.
1766046 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2241 }
2242 1766339 }
2243 1839951 c = MAPCOMBO(x,y);
2244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1839951 times.
1839951 if(check_icy(combobuf[c], type)) return c;
2245 1839951 return 0;
2246 1843607 }
2247
2248 13033776 static bool checkSV(int32_t x, int32_t y, int32_t flag)
2249 {
2250
8/8
✓ Branch 0 taken 13026978 times.
✓ Branch 1 taken 6798 times.
✓ Branch 2 taken 13018112 times.
✓ Branch 3 taken 8866 times.
✓ Branch 4 taken 13006480 times.
✓ Branch 5 taken 11632 times.
✓ Branch 6 taken 428460 times.
✓ Branch 7 taken 12578020 times.
13033776 if(x<0 || x>=world_w || y<0 || y>=world_h)
2251 455756 return false;
2252
2253 12578020 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
2254
2/4
✓ Branch 0 taken 12578020 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12578020 times.
12578020 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2255 return true;
2256
2257 12578020 change_rpos_handle_layer(rpos_handle, 1);
2258
2/2
✓ Branch 0 taken 7562442 times.
✓ Branch 1 taken 5015578 times.
12578020 if (rpos_handle.scr->is_valid())
2259
2/4
✓ Branch 0 taken 5015578 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5015578 times.
5015578 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2260 return true;
2261
2262 12578020 change_rpos_handle_layer(rpos_handle, 2);
2263
2/2
✓ Branch 0 taken 10873736 times.
✓ Branch 1 taken 1704284 times.
12578020 if (rpos_handle.scr->is_valid())
2264
2/4
✓ Branch 0 taken 1704284 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1704284 times.
1704284 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2265 return true;
2266
2267 12578020 return false;
2268 13033776 }
2269
2270 6579794 bool isSVLadder(int32_t x, int32_t y)
2271 {
2272 6579794 return checkSV(x, y, mfSIDEVIEWLADDER);
2273 }
2274
2275 6453982 bool isSVPlatform(int32_t x, int32_t y)
2276 {
2277 6453982 return checkSV(x, y, mfSIDEVIEWPLATFORM);
2278 }
2279
2280 6453982 bool checkSVLadderPlatform(int32_t x, int32_t y)
2281 {
2282
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6453982 times.
✓ Branch 2 taken 6453982 times.
✗ Branch 3 not taken.
6453982 return isSVPlatform(x,y) || (isSVLadder(x,y) && !isSVLadder(x,y-16));
2283 }
2284
2285 1637 bool isstepable(int32_t combo) //can use ladder on it
2286 {
2287
2/2
✓ Branch 0 taken 1631 times.
✓ Branch 1 taken 6 times.
1637 if(combo_class_buf[combobuf[combo].type].ladder_pass) return true;
2288
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(combo_class_buf[combobuf[combo].type].pit)
2289 {
2290 if(combobuf[combo].usrflags&cflag4)
2291 {
2292 int32_t ldrid = current_item_id(itype_ladder);
2293 return (ldrid > -1 && itemsbuf[ldrid].flags & item_flag1);
2294 }
2295 }
2296 6 return false;
2297 1637 }
2298
2299 32780 bool isHSGrabbable(newcombo const& cmb)
2300 {
2301
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 32407 times.
32780 if(cmb.type == cHSGRAB) return true;
2302 32407 return cmb.genflags & cflag1;
2303 32780 }
2304
2305 954 bool isSwitchHookable(newcombo const& cmb)
2306 {
2307
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 822 times.
954 if(cmb.type == cSWITCHHOOK) return true;
2308 822 return cmb.genflags & cflag2;
2309 954 }
2310
2311 61401 bool check_hshot(int32_t layer, int32_t x, int32_t y, bool switchhook, rpos_t *out_rpos, ffcdata **out_ffc)
2312 {
2313 61401 rpos_t cpos = rpos_t::None;
2314
2/2
✓ Branch 0 taken 64592 times.
✓ Branch 1 taken 125993 times.
61401 if(out_rpos)
2315 {
2316 125993 int32_t id = MAPCOMBO2(layer-1,x,y);
2317
2/2
✓ Branch 0 taken 28634 times.
✓ Branch 1 taken 97359 times.
125993 if(id > 0)
2318 {
2319 97359 newcombo const& cmb = combobuf[id];
2320
4/4
✓ Branch 0 taken 32738 times.
✓ Branch 1 taken 64621 times.
✓ Branch 2 taken 32296 times.
✓ Branch 3 taken 32325 times.
97359 cpos = (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb)) ? COMBOPOS_REGION(x,y) : rpos_t::None;
2321 32767 }
2322 61401 }
2323
2324 125993 ffcdata* ffc = nullptr;
2325
4/4
✓ Branch 0 taken 28389 times.
✓ Branch 1 taken 97604 times.
✓ Branch 2 taken 24996 times.
✓ Branch 3 taken 3393 times.
125993 if (out_ffc && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2326 {
2327 10361 for_some_ffcs([&](const ffc_handle_t& ffc_handle) {
2328
2/2
✓ Branch 0 taken 6853 times.
✓ Branch 1 taken 115 times.
6968 if (ffcIsAt(ffc_handle, x, y))
2329 {
2330 115 auto& cmb = ffc_handle.combo();
2331
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 37 times.
✓ Branch 3 taken 36 times.
115 if (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb))
2332 {
2333 79 ffc = ffc_handle.ffc;
2334 79 return false;
2335 }
2336 36 }
2337 6889 return true;
2338 6896 });
2339 3393 }
2340
2341
4/4
✓ Branch 0 taken 61401 times.
✓ Branch 1 taken 64592 times.
✓ Branch 2 taken 442 times.
✓ Branch 3 taken 60959 times.
125993 if (out_rpos && cpos != rpos_t::None) *out_rpos = cpos;
2342
4/4
✓ Branch 0 taken 28389 times.
✓ Branch 1 taken 97604 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 28382 times.
125993 if (out_ffc && ffc) *out_ffc = ffc;
2343
2/2
✓ Branch 0 taken 65034 times.
✓ Branch 1 taken 60959 times.
125993 return (cpos != rpos_t::None || ffc);
2344 }
2345
2346 5195 bool ishookshottable(int32_t bx, int32_t by)
2347 {
2348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5195 times.
5195 if(!_walkflag(bx,by,1))
2349 return true;
2350
2351
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5187 times.
5195 if (collide_object(bx, by, 1, 1))
2352 8 return false;
2353
2354 5187 bool ret = true;
2355
2/2
✓ Branch 0 taken 15561 times.
✓ Branch 1 taken 1900 times.
17461 for(int32_t i=2; i>=0; i--)
2356 {
2357 15561 int32_t c = MAPCOMBO2(i-1,bx,by);
2358 15561 int32_t t = combobuf[c].type;
2359
2360
6/6
✓ Branch 0 taken 5187 times.
✓ Branch 1 taken 10374 times.
✓ Branch 2 taken 3853 times.
✓ Branch 3 taken 1334 times.
✓ Branch 4 taken 1900 times.
✓ Branch 5 taken 1953 times.
15561 if(i == 0 && (t == cHOOKSHOTONLY || t == cLADDERHOOKSHOT)) return true;
2361
2362
3/4
✓ Branch 0 taken 11321 times.
✓ Branch 1 taken 953 times.
✓ Branch 2 taken 953 times.
✗ Branch 3 not taken.
13227 bool dried = (iswater_type(t) && DRIEDLAKE);
2363
2364 12274 int32_t b=1;
2365
2366
2/2
✓ Branch 0 taken 6109 times.
✓ Branch 1 taken 6165 times.
12274 if(bx&8) b<<=2;
2367
2368
2/2
✓ Branch 0 taken 3841 times.
✓ Branch 1 taken 8433 times.
12274 if(by&8) b<<=1;
2369
2370
7/8
✓ Branch 0 taken 2094 times.
✓ Branch 1 taken 10180 times.
✓ Branch 2 taken 2094 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1115 times.
✓ Branch 5 taken 979 times.
✓ Branch 6 taken 75 times.
✓ Branch 7 taken 904 times.
12274 if(combobuf[c].walk&b && !dried && !(combo_class_buf[t].ladder_pass && t!=cLADDERONLY) && t!=cHOOKSHOTONLY)
2371 904 ret = false;
2372 12274 }
2373
2374 1900 return ret;
2375 5195 }
2376
2377 10105 bool reveal_hidden_stairs(mapscr *s, int32_t screen, bool redraw)
2378 {
2379
4/4
✓ Branch 0 taken 9526 times.
✓ Branch 1 taken 579 times.
✓ Branch 2 taken 9526 times.
✓ Branch 3 taken 579 times.
10105 if((s->stairx || s->stairy) && s->secretcombo[sSTAIRS])
2380 {
2381 579 int pos = COMBOPOS(s->stairx,s->stairy);
2382 579 s->data[pos] = s->secretcombo[sSTAIRS];
2383 579 s->cset[pos] = s->secretcset[sSTAIRS];
2384 579 s->sflag[pos] = s->secretflag[sSTAIRS];
2385
2386
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 323 times.
579 if (redraw)
2387 {
2388 768 auto [x, y] = translate_screen_coordinates_to_world(screen, s->stairx, s->stairy);
2389 768 putcombo(scrollbuf,x,y,s->data[pos],s->cset[pos]);
2390 256 }
2391
2392 579 return true;
2393 }
2394
2395 9526 return false;
2396 10105 }
2397
2398 51764 screen_handles_t create_screen_handles_one(mapscr* base_scr)
2399 {
2400 DCHECK(base_scr->is_valid());
2401
2402 51764 screen_handles_t screen_handles{};
2403 51764 screen_handles[0] = {base_scr, base_scr, base_scr->screen, 0};
2404 51764 return screen_handles;
2405 }
2406
2407 56548811 screen_handles_t create_screen_handles(mapscr* base_scr)
2408 {
2409 DCHECK(get_scr(base_scr->screen) == base_scr);
2410 DCHECK(base_scr->is_valid());
2411
2412 56548811 int screen = base_scr->screen;
2413 screen_handles_t screen_handles;
2414 56548811 screen_handles[0] = {base_scr, base_scr, screen, 0};
2415
2/2
✓ Branch 0 taken 339292866 times.
✓ Branch 1 taken 56548811 times.
395841677 for (int i = 1; i <= 6; i++)
2416 339292866 screen_handles[i] = {base_scr, get_scr_layer_valid(screen, i), screen, i};
2417 56548811 return screen_handles;
2418 }
2419
2420 106202 bool remove_screenstatecombos2(const screen_handles_t& screen_handles, bool do_layers, int32_t what1, int32_t what2)
2421 {
2422 106202 mapscr* scr = screen_handles[0].scr;
2423 106202 bool didit=false;
2424
2425
2/2
✓ Branch 0 taken 106202 times.
✓ Branch 1 taken 18691552 times.
18797754 for(int32_t i=0; i<176; i++)
2426 {
2427 18691552 newcombo const& cmb = combobuf[scr->data[i]];
2428
2/2
✓ Branch 0 taken 326 times.
✓ Branch 1 taken 18691226 times.
18691552 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2429
4/4
✓ Branch 0 taken 18689693 times.
✓ Branch 1 taken 1533 times.
✓ Branch 2 taken 1102 times.
✓ Branch 3 taken 18688591 times.
18691226 if((cmb.type == what1) || (cmb.type== what2))
2430 {
2431 2635 scr->data[i]++;
2432 2635 didit=true;
2433 2635 }
2434 18691226 }
2435
2436
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 106110 times.
106202 if (do_layers)
2437 {
2438
2/2
✓ Branch 0 taken 636660 times.
✓ Branch 1 taken 106110 times.
742770 for(int32_t j=1; j<=6; j++)
2439 {
2440 636660 mapscr* layer_scr = screen_handles[j].scr;
2441
2/2
✓ Branch 0 taken 173044 times.
✓ Branch 1 taken 463616 times.
636660 if (!layer_scr) continue;
2442
2443
2/2
✓ Branch 0 taken 30455744 times.
✓ Branch 1 taken 173044 times.
30628788 for(int32_t i=0; i<176; i++)
2444 {
2445 30455744 newcombo const& cmb = combobuf[layer_scr->data[i]];
2446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30455744 times.
30455744 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2447
4/4
✓ Branch 0 taken 30455661 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 265 times.
✓ Branch 3 taken 30455396 times.
30455744 if((cmb.type== what1) || (cmb.type== what2))
2448 {
2449 348 layer_scr->data[i]++;
2450 348 didit=true;
2451 348 }
2452 30455744 }
2453 173044 }
2454 106110 }
2455
2456 // 'do_layers' also means that this is called on an active temp screen, so update its ffcs.
2457
3/4
✓ Branch 0 taken 20406 times.
✓ Branch 1 taken 85796 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20406 times.
106202 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && do_layers)
2458 {
2459 20406 word c = scr->numFFC();
2460
2/2
✓ Branch 0 taken 73350 times.
✓ Branch 1 taken 20406 times.
93756 for(word i=0; i<c; i++)
2461 {
2462 73350 ffcdata* ffc = &scr->ffcs[i];
2463 73350 newcombo const& cmb = combobuf[ffc->data];
2464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73350 times.
73350 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2465
2/4
✓ Branch 0 taken 73350 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73350 times.
73350 if((cmb.type== what1) || (cmb.type== what2))
2466 {
2467 zc_ffc_modify(*ffc, 1);
2468 didit=true;
2469 }
2470 73350 }
2471 20406 }
2472
2473 106202 return didit;
2474 }
2475
2476 14 bool remove_xstatecombos(const screen_handles_t& screen_handles, byte xflag, bool triggers)
2477 {
2478 14 int screen = screen_handles[0].scr->screen;
2479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2480 14 return remove_xstatecombos_mi(screen_handles, mi, xflag, triggers);
2481 }
2482 471582510 bool remove_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, byte xflag, bool triggers)
2483 {
2484 471582510 bool didit=false;
2485
2/2
✓ Branch 0 taken 471543517 times.
✓ Branch 1 taken 38993 times.
471582510 if(!getxmapflag_mi(mi, 1<<xflag)) return false;
2486
2487 38993 mapscr* s = screen_handles[0].scr;
2488 38993 int screen = s->screen;
2489 38993 bool is_active_screen = is_in_current_region(s);
2490
2491 31393569 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2492
4/4
✓ Branch 0 taken 31342960 times.
✓ Branch 1 taken 11616 times.
✓ Branch 2 taken 31341138 times.
✓ Branch 3 taken 1822 times.
31354576 if(triggers && force_ex_trigger_any(rpos_handle, xflag))
2493 1822 didit = true;
2494
2/2
✓ Branch 0 taken 63627 times.
✓ Branch 1 taken 31289127 times.
31352754 else switch (rpos_handle.ctype())
2495 {
2496 case cLOCKBLOCK: case cLOCKBLOCK2:
2497 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2498 case cCHEST: case cCHEST2:
2499 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2500 case cBOSSCHEST: case cBOSSCHEST2:
2501 {
2502 63627 auto& cmb = rpos_handle.combo();
2503
2/2
✓ Branch 0 taken 62059 times.
✓ Branch 1 taken 1568 times.
63627 if(!(cmb.usrflags&cflag16)) return; //custom state instead of normal state
2504
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 62030 times.
62059 if(cmb.attribytes[5] == xflag)
2505 {
2506 29 rpos_handle.increment_data();
2507 29 didit=true;
2508 29 }
2509 62059 break;
2510 }
2511 }
2512 31354576 });
2513
2514
4/4
✓ Branch 0 taken 38952 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 29332 times.
✓ Branch 3 taken 9620 times.
38993 if (is_active_screen && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2515 {
2516 29332 word c = s->numFFC();
2517 29332 int screen_index_offset = get_region_screen_offset(screen);
2518
2/2
✓ Branch 0 taken 36840 times.
✓ Branch 1 taken 29332 times.
66172 for (uint8_t i = 0; i < c; i++)
2519 {
2520 36840 auto ffc_handle = *s->getFFCHandle(i, screen_index_offset);
2521 36840 auto& cmb = ffc_handle.combo();
2522
3/4
✓ Branch 0 taken 36840 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36824 times.
✓ Branch 3 taken 16 times.
36840 if(triggers && force_ex_trigger_ffc_any(ffc_handle, xflag))
2523 16 didit = true;
2524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36824 times.
36824 else switch(cmb.type)
2525 {
2526 case cLOCKBLOCK: case cLOCKBLOCK2:
2527 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2528 case cCHEST: case cCHEST2:
2529 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2530 case cBOSSCHEST: case cBOSSCHEST2:
2531 {
2532 if(!(cmb.usrflags&cflag16)) continue; //custom state instead of normal state
2533 if(cmb.attribytes[5] == xflag)
2534 {
2535 zc_ffc_modify(*ffc_handle.ffc, 1);
2536 didit=true;
2537 }
2538 break;
2539 }
2540 }
2541 36840 }
2542 29332 }
2543
2544 38993 return didit;
2545 471582510 }
2546
2547 14684959 void clear_xstatecombos(const screen_handles_t& screen_handles, bool triggers)
2548 {
2549 14684959 int screen = screen_handles[0].screen;
2550
2/2
✓ Branch 0 taken 387833 times.
✓ Branch 1 taken 14297126 times.
14684959 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2551 14684959 clear_xstatecombos_mi(screen_handles, mi, triggers);
2552 14684959 }
2553
2554 14736953 void clear_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2555 {
2556
2/2
✓ Branch 0 taken 471582496 times.
✓ Branch 1 taken 14736953 times.
486319449 for (int q = 0; q < 32; ++q)
2557 {
2558 471582496 remove_xstatecombos_mi(screen_handles, mi, q, triggers);
2559 471582496 }
2560 14736953 }
2561
2562 bool remove_xdoors(const screen_handles_t& screen_handles, uint dir, uint ind, bool triggers)
2563 {
2564 int screen = screen_handles[0].screen;
2565 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2566 return remove_xdoors_mi(screen_handles, mi, dir, ind, triggers);
2567 }
2568 471582496 bool remove_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, uint dir, uint ind, bool triggers)
2569 {
2570 471582496 bool didit=false;
2571
1/2
✓ Branch 0 taken 471582496 times.
✗ Branch 1 not taken.
471582496 if (!getxdoor_mi(mi, dir, ind)) return false;
2572
2573 mapscr* scr = screen_handles[0].scr;
2574 int screen = scr->screen;
2575 bool is_active_screen = is_in_current_region(scr);
2576
2577 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2578 if (triggers && force_ex_door_trigger_any(rpos_handle, dir, ind))
2579 didit = true;
2580 else; //future door combo types?
2581 });
2582
2583 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && is_active_screen)
2584 {
2585 word c = scr->numFFC();
2586 int screen_index_offset = get_region_screen_offset(screen);
2587 for (uint8_t i = 0; i < c; i++)
2588 {
2589 auto ffc_handle = *scr->getFFCHandle(i, screen_index_offset);
2590 if (triggers && force_ex_door_trigger_ffc_any(ffc_handle, dir, ind))
2591 didit = true;
2592 else; //future door combo types?
2593 }
2594 }
2595
2596 return didit;
2597 471582496 }
2598
2599 14684959 void clear_xdoors(const screen_handles_t& screen_handles, bool triggers)
2600 {
2601 14684959 int screen = screen_handles[0].screen;
2602
2/2
✓ Branch 0 taken 387833 times.
✓ Branch 1 taken 14297126 times.
14684959 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2603 14684959 return clear_xdoors_mi(screen_handles, mi, triggers);
2604 }
2605
2606 14736953 void clear_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2607 {
2608
2/2
✓ Branch 0 taken 58947812 times.
✓ Branch 1 taken 14736953 times.
73684765 for (int dir = 0; dir < 4; ++dir)
2609
2/2
✓ Branch 0 taken 471582496 times.
✓ Branch 1 taken 58947812 times.
530530308 for (int q = 0; q < 8; ++q)
2610 530530308 remove_xdoors_mi(screen_handles, mi, dir, q, triggers);
2611 14736953 }
2612
2613 763 bool remove_lockblocks(const screen_handles_t& screen_handles)
2614 {
2615 763 return remove_screenstatecombos2(screen_handles, true, cLOCKBLOCK, cLOCKBLOCK2);
2616 }
2617
2618 98 bool remove_bosslockblocks(const screen_handles_t& screen_handles)
2619 {
2620 98 return remove_screenstatecombos2(screen_handles, true, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
2621 }
2622
2623 76553 bool remove_chests(const screen_handles_t& screen_handles)
2624 {
2625 76553 return remove_screenstatecombos2(screen_handles, true, cCHEST, cCHEST2);
2626 }
2627
2628 2484 bool remove_lockedchests(const screen_handles_t& screen_handles)
2629 {
2630 2484 return remove_screenstatecombos2(screen_handles, true, cLOCKEDCHEST, cLOCKEDCHEST2);
2631 }
2632
2633 26212 bool remove_bosschests(const screen_handles_t& screen_handles)
2634 {
2635 26212 return remove_screenstatecombos2(screen_handles, true, cBOSSCHEST, cBOSSCHEST2);
2636 }
2637
2638 1384355 void delete_fireball_shooter(const rpos_handle_t& rpos_handle)
2639 {
2640 1384355 int32_t ct=rpos_handle.ctype();
2641
2642
6/6
✓ Branch 0 taken 1383735 times.
✓ Branch 1 taken 620 times.
✓ Branch 2 taken 1383483 times.
✓ Branch 3 taken 252 times.
✓ Branch 4 taken 1383375 times.
✓ Branch 5 taken 108 times.
1384355 if(ct!=cL_STATUE && ct!=cR_STATUE && ct!=cC_STATUE)
2643 1383375 return;
2644
2645 2465 auto [cx, cy] = rpos_handle.xy();
2646
3/4
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 620 times.
✓ Branch 3 taken 108 times.
980 switch(ct)
2647 {
2648 case cL_STATUE:
2649 620 cx += 4;
2650 620 cy += 7;
2651 620 break;
2652
2653 case cR_STATUE:
2654 252 cx -= 8;
2655 252 cy -= 1;
2656 252 break;
2657
2658 case cC_STATUE:
2659 108 break;
2660 }
2661
2662
2/2
✓ Branch 0 taken 980 times.
✓ Branch 1 taken 1485 times.
2465 for(int32_t j=0; j<guys.Count(); j++)
2663 {
2664 // Finds the smallest enemy ID
2665
9/10
✓ Branch 0 taken 399 times.
✓ Branch 1 taken 1086 times.
✓ Branch 2 taken 399 times.
✓ Branch 3 taken 1086 times.
✓ Branch 4 taken 346 times.
✓ Branch 5 taken 53 times.
✓ Branch 6 taken 346 times.
✓ Branch 7 taken 53 times.
✓ Branch 8 taken 346 times.
✗ Branch 9 not taken.
2970 if((int32_t(guys.spr(j)->x)==cx)&&(int32_t(guys.spr(j)->y)==cy)&&(guysbuf[(guys.spr(j)->id)&0xFFF].flags & guy_fire))
2666 {
2667 346 guys.del(j);
2668 346 }
2669 1485 }
2670 1384355 }
2671
2672 15 static int32_t findtrigger(int32_t screen)
2673 {
2674 15 int32_t checkflag=0;
2675 15 int32_t ret = 0;
2676
2677 mapscr* screens[7];
2678
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 15 times.
120 for (int32_t j = 0; j <= 6; j++)
2679 {
2680 105 screens[j] = get_scr_layer_valid(screen, j);
2681 105 }
2682
2683 15 bool sflag = false;
2684
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 15 times.
2655 for(word j=0; j<176; j++)
2685 {
2686
2/2
✓ Branch 0 taken 26752 times.
✓ Branch 1 taken 2640 times.
29392 for(int32_t layer = -1; layer < 6; ++layer)
2687 {
2688 26752 mapscr* scr = screens[layer+1];
2689
2/2
✓ Branch 0 taken 16544 times.
✓ Branch 1 taken 10208 times.
26752 if (!scr) continue;
2690
2691
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if(sflag)
2692 8272 checkflag = scr->sflag[j];
2693 else
2694 8272 checkflag = combobuf[scr->data[j]].flag;
2695 16544 sflag = !sflag;
2696
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if (sflag) --layer;
2697
2698
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 16534 times.
16544 switch(checkflag)
2699 {
2700 case mfANYFIRE:
2701 case mfSTRONGFIRE:
2702 case mfMAGICFIRE:
2703 case mfDIVINEFIRE:
2704 case mfARROW:
2705 case mfSARROW:
2706 case mfGARROW:
2707 case mfSBOMB:
2708 case mfBOMB:
2709 case mfBRANG:
2710 case mfMBRANG:
2711 case mfFBRANG:
2712 case mfWANDMAGIC:
2713 case mfREFMAGIC:
2714 case mfREFFIREBALL:
2715 case mfSWORD:
2716 case mfWSWORD:
2717 case mfMSWORD:
2718 case mfXSWORD:
2719 case mfSWORDBEAM:
2720 case mfWSWORDBEAM:
2721 case mfMSWORDBEAM:
2722 case mfXSWORDBEAM:
2723 case mfHOOKSHOT:
2724 case mfWAND:
2725 case mfHAMMER:
2726 case mfSTRIKE:
2727 10 ret += 1;
2728 10 break;
2729 }
2730 16544 }
2731 2640 }
2732
2733 15 return ret;
2734 }
2735
2736 11734 static void log_trigger_secret_reason(TriggerSource source)
2737 {
2738
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11295 times.
11734 if (source == TriggerSource::Singular)
2739 {
2740 439 Z_eventlog("Restricted Screen Secrets triggered\n");
2741 439 }
2742 else
2743 {
2744 11295 const char* source_str = "";
2745
7/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 7178 times.
✓ Branch 3 taken 856 times.
✓ Branch 4 taken 2732 times.
✓ Branch 5 taken 475 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 49 times.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
11295 switch (source)
2746 {
2747 case TriggerSource::Singular: break;
2748 7178 case TriggerSource::Unspecified: source_str = "unspecified means"; break;
2749 856 case TriggerSource::EnemiesScreenFlag: source_str = "the 'Enemies->Secret' screen flag"; break;
2750 2732 case TriggerSource::SecretsScreenState: source_str = "the 'Secrets' screen state"; break;
2751 475 case TriggerSource::Script: source_str = "a script"; break;
2752 1 case TriggerSource::ItemsSecret: source_str = "Items->Secrets"; break;
2753 49 case TriggerSource::GenericCombo: source_str = "Generic Combo"; break;
2754 4 case TriggerSource::LightTrigger: source_str = "Light Triggers"; break;
2755 case TriggerSource::SCC: source_str = "SCC"; break;
2756 case TriggerSource::CheatTemp: source_str = "Cheat (Temp)"; break;
2757 case TriggerSource::CheatPerm: source_str = "Cheat (Perm)"; break;
2758 }
2759 11295 Z_eventlog("Screen Secrets triggered by %s\n", source_str);
2760 }
2761 11734 }
2762
2763 // single:
2764 // >-1 : the singular triggering combo
2765 // -1: triggered by some other cause
2766 11526 void trigger_secrets_for_screen(TriggerSource source, mapscr* scr, bool high16only, int32_t single)
2767 {
2768 11526 log_trigger_secret_reason(source);
2769
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11087 times.
11526 if (single < 0)
2770 11087 get_screen_state(scr->screen).triggered_secrets = true;
2771
2772 11526 bool do_replay_comment = true;
2773 11526 bool from_active_screen = true;
2774 11526 trigger_secrets_for_screen_internal(create_screen_handles(scr), from_active_screen, high16only, single, do_replay_comment);
2775
2776 // Respect secret state carryovers for active screens.
2777
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11087 times.
11526 if (single >= 0) return;
2778 11087 int flag = mSECRET;
2779 11087 int cmap = scr->map;
2780 11087 int cscr = scr->screen;
2781 11087 int nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
2782 11087 int nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
2783
2784 11087 std::vector<int32_t> done;
2785
2/2
✓ Branch 0 taken 10900 times.
✓ Branch 1 taken 187 times.
11087 bool looped = (nmap==cmap+1 && nscr==cscr);
2786
2787
6/6
✓ Branch 0 taken 629 times.
✓ Branch 1 taken 11010 times.
✓ Branch 2 taken 77 times.
✓ Branch 3 taken 552 times.
✓ Branch 4 taken 552 times.
✓ Branch 5 taken 11087 times.
11639 while((nmap!=0) && !looped && !(nscr>=128))
2788 {
2789
9/10
✓ Branch 0 taken 385 times.
✓ Branch 1 taken 167 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 301 times.
✓ Branch 4 taken 74 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 74 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 70 times.
552 if (nmap - 1 == cur_map && is_in_current_region(nscr) && (scr->nocarry&flag)!=flag && !get_screen_state(nscr).triggered_secrets)
2790 {
2791
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
2792
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 trigger_secrets_for_screen_internal(create_screen_handles(get_scr(nscr)), from_active_screen, high16only, single, do_replay_comment);
2793
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 get_screen_state(nscr).triggered_secrets = true;
2794 4 }
2795
2796 552 cmap=nmap;
2797 552 cscr=nscr;
2798 552 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
2799 552 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
2800
2801
2/2
✓ Branch 0 taken 1101 times.
✓ Branch 1 taken 552 times.
1653 for(auto it = done.begin(); it != done.end(); it++)
2802 {
2803
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 77 times.
1101 if(*it == ((nmap-1)<<7)+nscr)
2804 77 looped = true;
2805 1101 }
2806
2807
1/2
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
552 done.push_back(((nmap-1)<<7)+nscr);
2808 }
2809 11526 }
2810
2811 2437 void trigger_secrets_for_screen(TriggerSource source, int32_t screen, bool high16only, int32_t single)
2812 {
2813 2437 trigger_secrets_for_screen(source, get_scr(screen), high16only, single);
2814 2437 }
2815
2816 17999 void trigger_secrets_for_screen_internal(const screen_handles_t& screen_handles, bool from_active_screen, bool high16only, int32_t single, bool do_replay_comment)
2817 {
2818 17999 mapscr* scr = screen_handles[0].scr;
2819 17999 int screen = scr->screen;
2820
2821 // TODO(replays): No real reason for "do_replay_comment" to exist - I just did not want to update many replays when fixing
2822 // slopes in sideview mode (which required loading nearby screens in loadscr).
2823 // TODO(replays): This should just use `screen`.
2824
3/4
✓ Branch 0 taken 17999 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 535 times.
✓ Branch 3 taken 17464 times.
17999 if (replay_is_active() && do_replay_comment)
2825
4/6
✓ Branch 0 taken 11530 times.
✓ Branch 1 taken 5934 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11530 times.
✓ Branch 4 taken 17464 times.
✗ Branch 5 not taken.
17464 replay_step_comment(fmt::format("trigger secrets scr={}", from_active_screen && scr != special_warp_return_scr ? screen : cur_screen));
2826
2827
2/2
✓ Branch 0 taken 6469 times.
✓ Branch 1 taken 11530 times.
17999 if (from_active_screen)
2828 {
2829 5440178 for_every_combo_in_screen(screen_handles, [&](const auto& handle) {
2830 5428648 auto cid = handle.data();
2831 5428648 auto& cmb = handle.combo();
2832
4/4
✓ Branch 0 taken 5426940 times.
✓ Branch 1 taken 229446 times.
✓ Branch 2 taken 1688 times.
✓ Branch 3 taken 182 times.
5658256 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
2833 {
2834 229628 auto& trig = cmb.triggers[idx];
2835
3/4
✓ Branch 0 taken 65534 times.
✓ Branch 1 taken 163912 times.
✓ Branch 2 taken 182 times.
✗ Branch 3 not taken.
229628 if (trig.triggerflags[2] & combotriggerSECRETSTR)
2836 {
2837 163912 do_trigger_combo(handle, idx, ctrigSECRETS);
2838
2/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 163892 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
163912 if(handle.data() != cid) break;
2839 163892 }
2840 229608 }
2841 5428648 });
2842 11530 }
2843
2844 17999 int32_t ft=0; //Flag trigger?
2845 17999 int32_t msflag=0; // Misc. secret flag
2846
2847
2/2
✓ Branch 0 taken 3167824 times.
✓ Branch 1 taken 17999 times.
3185823 for(int32_t i=0; i<176; i++) //Do the 'trigger flags' (non 16-31)
2848 {
2849
4/4
✓ Branch 0 taken 77264 times.
✓ Branch 1 taken 3090560 times.
✓ Branch 2 taken 439 times.
✓ Branch 3 taken 76825 times.
3167824 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2850
2851 // Remember the misc. secret flag; if triggered, use this instead
2852
4/4
✓ Branch 0 taken 114508 times.
✓ Branch 1 taken 2976491 times.
✓ Branch 2 taken 49462 times.
✓ Branch 3 taken 65046 times.
3090999 if(scr->sflag[i]>=mfSECRETS01 && scr->sflag[i]<=mfSECRETS16)
2853 65046 msflag=sSECRET01+(scr->sflag[i]-mfSECRETS01);
2854
4/4
✓ Branch 0 taken 47230 times.
✓ Branch 1 taken 2978723 times.
✓ Branch 2 taken 46999 times.
✓ Branch 3 taken 231 times.
3025953 else if(combobuf[scr->data[i]].flag>=mfSECRETS01 && combobuf[scr->data[i]].flag<=mfSECRETS16)
2855 231 msflag=sSECRET01+(combobuf[scr->data[i]].flag-mfSECRETS01);
2856 else
2857 3025722 msflag=0;
2858
2859
4/4
✓ Branch 0 taken 921256 times.
✓ Branch 1 taken 2169743 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 921184 times.
3090999 if(!high16only || single>=0)
2860 {
2861 2169815 int32_t newflag = -1;
2862
2863
2/2
✓ Branch 0 taken 4339630 times.
✓ Branch 1 taken 2169815 times.
6509445 for(int32_t iter=0; iter<2; ++iter)
2864 {
2865 4339630 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
2866
2867
2/2
✓ Branch 0 taken 2169815 times.
✓ Branch 1 taken 2169815 times.
4339630 if(iter==1) checkflag=scr->sflag[i]; //Placed
2868
2869 4339630 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2870
2/2
✓ Branch 0 taken 4327396 times.
✓ Branch 1 taken 12234 times.
4339630 if (ft != -1) //Change the combos for the secret
2871 {
2872 // Use misc. secret flag instead if one is present
2873
2/2
✓ Branch 0 taken 12202 times.
✓ Branch 1 taken 32 times.
12234 if(msflag!=0)
2874 32 ft=msflag;
2875
2876 12234 rpos_handle_t rpos_handle;
2877
2/2
✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 5867 times.
12234 if (from_active_screen)
2878 {
2879 5867 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
2880 5867 screen_combo_modify_preroutine(rpos_handle);
2881 5867 }
2882
2883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12234 times.
12234 if(ft==sSECNEXT)
2884 {
2885 scr->data[i]++;
2886 }
2887 else
2888 {
2889 12234 scr->data[i] = scr->secretcombo[ft];
2890 12234 scr->cset[i] = scr->secretcset[ft];
2891 }
2892 12234 newflag = scr->secretflag[ft];
2893
2894
2/2
✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 5867 times.
12234 if (from_active_screen)
2895 5867 screen_combo_modify_postroutine(rpos_handle);
2896 12234 }
2897 4339630 }
2898
2899
2/2
✓ Branch 0 taken 2157587 times.
✓ Branch 1 taken 12228 times.
2169815 if(newflag >-1) scr->sflag[i] = newflag; //Tiered secret
2900
2901
2/2
✓ Branch 0 taken 13018890 times.
✓ Branch 1 taken 2169815 times.
15188705 for(int32_t j=1; j<=6; j++) //Layers
2902 {
2903 13018890 mapscr* layer_scr = screen_handles[j].scr;
2904
2/2
✓ Branch 0 taken 3183685 times.
✓ Branch 1 taken 9835205 times.
13018890 if (!layer_scr) continue;
2905
2906
3/4
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 3182960 times.
✓ Branch 2 taken 725 times.
✗ Branch 3 not taken.
3183685 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2907
2908 3183685 int32_t newflag2 = -1;
2909
2910 // Remember the misc. secret flag; if triggered, use this instead
2911
4/4
✓ Branch 0 taken 14180 times.
✓ Branch 1 taken 3169505 times.
✓ Branch 2 taken 4773 times.
✓ Branch 3 taken 9407 times.
3183685 if(layer_scr->sflag[i]>=mfSECRETS01 && layer_scr->sflag[i]<=mfSECRETS16)
2912 9407 msflag=sSECRET01+(layer_scr->sflag[i]-mfSECRETS01);
2913
4/4
✓ Branch 0 taken 126931 times.
✓ Branch 1 taken 3047347 times.
✓ Branch 2 taken 126560 times.
✓ Branch 3 taken 371 times.
3174278 else if(combobuf[layer_scr->data[i]].flag>=mfSECRETS01 && combobuf[layer_scr->data[i]].flag<=mfSECRETS16)
2914 371 msflag=sSECRET01+(combobuf[layer_scr->data[i]].flag-mfSECRETS01);
2915 else
2916 3173907 msflag=0;
2917
2918
2/2
✓ Branch 0 taken 6367370 times.
✓ Branch 1 taken 3183685 times.
9551055 for(int32_t iter=0; iter<2; ++iter)
2919 {
2920 6367370 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
2921
2/2
✓ Branch 0 taken 3183685 times.
✓ Branch 1 taken 3183685 times.
6367370 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
2922
2923 6367370 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2924
2/2
✓ Branch 0 taken 6366892 times.
✓ Branch 1 taken 478 times.
6367370 if (ft != -1) //Change the combos for the secret
2925 {
2926 // Use misc. secret flag instead if one is present
2927
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 2 times.
478 if(msflag!=0)
2928 2 ft=msflag;
2929
2930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
478 if(ft==sSECNEXT)
2931 {
2932 layer_scr->data[i]++;
2933 }
2934 else
2935 {
2936 478 layer_scr->data[i] = layer_scr->secretcombo[ft];
2937 478 layer_scr->cset[i] = layer_scr->secretcset[ft];
2938 }
2939 478 newflag2 = layer_scr->secretflag[ft];
2940 478 int32_t c=layer_scr->data[i];
2941 478 int32_t cs=layer_scr->cset[i];
2942
2943
3/4
✓ Branch 0 taken 406 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 406 times.
✗ Branch 3 not taken.
478 if (from_active_screen && combobuf[c].type==cSPINTILE1) //Surely this means we can have spin tiles on layers 3+? Isn't that bad? ~Joe123
2944 {
2945 auto [offx, offy] = translate_screen_coordinates_to_world(screen, COMBOX(i), COMBOY(i));
2946 addenemy(screen,offx,offy,(cs<<12)+eSPINTILE1,combobuf[c].o_tile+zc_max(1,combobuf[c].frames));
2947 }
2948 478 }
2949 6367370 }
2950
2951
2/2
✓ Branch 0 taken 478 times.
✓ Branch 1 taken 3183207 times.
3183685 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered secret
2952 3183685 }
2953 2169815 }
2954 3090999 }
2955
2956 17999 word c = scr->numFFC();
2957
2/2
✓ Branch 0 taken 506903 times.
✓ Branch 1 taken 17999 times.
524902 for(word i=0; i<c; i++) //FFC 'trigger flags'
2958 {
2959
3/4
✓ Branch 0 taken 492983 times.
✓ Branch 1 taken 13920 times.
✓ Branch 2 taken 13920 times.
✗ Branch 3 not taken.
506903 if(single>=0) if(i+176!=single) continue;
2960
2961
3/4
✓ Branch 0 taken 166605 times.
✓ Branch 1 taken 326378 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 166605 times.
492983 if((!high16only)||(single>=0))
2962 {
2963 //for (int32_t iter=0; iter<1; ++iter) // Only one kind of FFC flag now.
2964 {
2965 326378 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
2966 //No placed flags yet
2967
2968 326378 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2969
2/2
✓ Branch 0 taken 326347 times.
✓ Branch 1 taken 31 times.
326378 if (ft != -1) //Change the ffc's combo
2970 {
2971
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if(ft==sSECNEXT)
2972 {
2973 zc_ffc_modify(scr->ffcs[i], 1);
2974 }
2975 else
2976 {
2977 31 zc_ffc_set(scr->ffcs[i], scr->secretcombo[ft]);
2978 31 scr->ffcs[i].cset = scr->secretcset[ft];
2979 }
2980 31 }
2981 }
2982 326378 }
2983 492983 }
2984
2985
2/2
✓ Branch 0 taken 15602 times.
✓ Branch 1 taken 2397 times.
17999 if(checktrigger) //Hit all triggers->16-31
2986 {
2987 2397 checktrigger=false;
2988
2989
2/2
✓ Branch 0 taken 2388 times.
✓ Branch 1 taken 9 times.
2397 if(scr->flags6&fTRIGGERF1631)
2990 {
2991 9 int32_t tr = findtrigger(screen); //Normal flags
2992
2993
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 if(tr)
2994 {
2995 5 Z_eventlog("Hit All Triggers->16-31 not fulfilled (%d trigger flag%s remain).\n", tr, tr>1?"s":"");
2996 5 goto endhe;
2997 }
2998 4 }
2999 2392 }
3000
3001
2/2
✓ Branch 0 taken 3166944 times.
✓ Branch 1 taken 17994 times.
3184938 for(int32_t i=0; i<176; i++) // Do the 16-31 secrets
3002 {
3003 //If it's an enemies->secret screen, only do the high 16 if told to
3004 //That way you can have secret and burn/bomb entrance separately
3005 3166944 bool old_enem_secret = get_qr(qr_ENEMIES_SECRET_ONLY_16_31);
3006
6/6
✓ Branch 0 taken 2780624 times.
✓ Branch 1 taken 386320 times.
✓ Branch 2 taken 85184 times.
✓ Branch 3 taken 3081760 times.
✓ Branch 4 taken 19536 times.
✓ Branch 5 taken 65648 times.
3166944 if(((!(old_enem_secret && (scr->flags2&fCLEARSECRET)) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM))
3007 {
3008 3101296 int32_t newflag = -1;
3009
3010
2/2
✓ Branch 0 taken 6202592 times.
✓ Branch 1 taken 3101296 times.
9303888 for(int32_t iter=0; iter<2; ++iter)
3011 {
3012 6202592 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
3013
3014
2/2
✓ Branch 0 taken 3101296 times.
✓ Branch 1 taken 3101296 times.
6202592 if(iter==1) checkflag=scr->sflag[i]; //Placed
3015
3016
4/4
✓ Branch 0 taken 161182 times.
✓ Branch 1 taken 6041410 times.
✓ Branch 2 taken 94853 times.
✓ Branch 3 taken 66329 times.
6202592 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3017 {
3018 66329 rpos_handle_t rpos_handle;
3019
2/2
✓ Branch 0 taken 9951 times.
✓ Branch 1 taken 56378 times.
66329 if (from_active_screen)
3020 {
3021 56378 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
3022 56378 screen_combo_modify_preroutine(rpos_handle);
3023 56378 }
3024
3025 66329 scr->data[i] = scr->secretcombo[checkflag-16+4];
3026 66329 scr->cset[i] = scr->secretcset[checkflag-16+4];
3027 66329 newflag = scr->secretflag[checkflag-16+4];
3028
3029
2/2
✓ Branch 0 taken 9951 times.
✓ Branch 1 taken 56378 times.
66329 if (from_active_screen)
3030 56378 screen_combo_modify_postroutine(rpos_handle);
3031 66329 }
3032 6202592 }
3033
3034
2/2
✓ Branch 0 taken 3034991 times.
✓ Branch 1 taken 66305 times.
3101296 if(newflag >-1) scr->sflag[i] = newflag; //Tiered flag
3035
3036
2/2
✓ Branch 0 taken 18607776 times.
✓ Branch 1 taken 3101296 times.
21709072 for(int32_t j=1; j<=6; j++) //Layers
3037 {
3038 18607776 mapscr* layer_scr = screen_handles[j].scr;
3039
2/2
✓ Branch 0 taken 4864640 times.
✓ Branch 1 taken 13743136 times.
18607776 if (!layer_scr) continue;
3040
3041 4864640 int32_t newflag2 = -1;
3042
3043
2/2
✓ Branch 0 taken 9729280 times.
✓ Branch 1 taken 4864640 times.
14593920 for(int32_t iter=0; iter<2; ++iter)
3044 {
3045 9729280 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
3046
3047
2/2
✓ Branch 0 taken 4864640 times.
✓ Branch 1 taken 4864640 times.
9729280 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
3048
3049
4/4
✓ Branch 0 taken 151244 times.
✓ Branch 1 taken 9578036 times.
✓ Branch 2 taken 131622 times.
✓ Branch 3 taken 19622 times.
9729280 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3050 {
3051 19622 layer_scr->data[i] = layer_scr->secretcombo[checkflag-16+4];
3052 19622 layer_scr->cset[i] = layer_scr->secretcset[checkflag-16+4];
3053 19622 newflag2 = layer_scr->secretflag[checkflag-16+4];
3054 19622 }
3055 9729280 }
3056
3057
2/2
✓ Branch 0 taken 4845018 times.
✓ Branch 1 taken 19622 times.
4864640 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered flag
3058 4864640 }
3059 3101296 }
3060 3166944 }
3061
3062
2/2
✓ Branch 0 taken 506743 times.
✓ Branch 1 taken 17994 times.
524737 for(word i=0; i<c; i++) // FFCs
3063 {
3064
6/6
✓ Branch 0 taken 466852 times.
✓ Branch 1 taken 39891 times.
✓ Branch 2 taken 15367 times.
✓ Branch 3 taken 491376 times.
✓ Branch 4 taken 3530 times.
✓ Branch 5 taken 11837 times.
506743 if((!(scr->flags2&fCLEARSECRET) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM)
3065 {
3066 494906 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
3067
3068 //No placed flags yet
3069
4/4
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 494838 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 12 times.
494906 if((checkflag > 15)&&(checkflag < 32)) //If we find a flag, change the combo
3070 {
3071
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 if (from_active_screen)
3072 9 zc_ffc_set(scr->ffcs[i], scr->secretcombo[checkflag - 16 + 4]);
3073 else
3074 3 scr->ffcs[i].data = scr->secretcombo[checkflag - 16 + 4];
3075 12 scr->ffcs[i].cset = scr->secretcset[checkflag-16+4];
3076 12 }
3077 494906 }
3078 524737 }
3079
3080 endhe:
3081
3082
1/2
✓ Branch 0 taken 17999 times.
✗ Branch 1 not taken.
17999 if (scr->flags4&fDISABLETIME) //Finish timed warp if 'Secrets Disable Timed Warp'
3083 {
3084 if (from_active_screen)
3085 activated_timed_warp = true;
3086 scr->timedwarptics = 0;
3087 }
3088 17999 }
3089
3090 // x,y are world coordinates.
3091 // Returns true if there is a flag (either combo, screen, or ffc) at (x, y).
3092 // Out parameters will be set if the flag is Trigger->Self, which modifies how secrets will be triggered.
3093 13497488 static bool has_flag_trigger(int32_t x, int32_t y, int32_t flag, rpos_t& out_rpos, bool& out_single16)
3094 {
3095
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13497488 times.
13497488 if (!is_in_world_bounds(x, y)) return false;
3096
3097 13497488 bool found_cflag = false;
3098 13497488 bool found_nflag = false;
3099 13497488 bool single16 = false;
3100 13497488 rpos_t rpos = rpos_t::None;
3101
3102
2/2
✓ Branch 0 taken 13495404 times.
✓ Branch 1 taken 94470224 times.
107965628 for (int32_t layer = -1; layer < 6; layer++)
3103 {
3104
2/2
✓ Branch 0 taken 94468140 times.
✓ Branch 1 taken 2084 times.
94470224 if (MAPFLAG2(layer, x, y) == flag)
3105 {
3106 2084 found_nflag = true;
3107 2084 break;
3108 }
3109 94468140 }
3110
3111
2/2
✓ Branch 0 taken 13497184 times.
✓ Branch 1 taken 94481140 times.
107978324 for (int32_t layer = -1; layer < 6; layer++)
3112 {
3113
2/2
✓ Branch 0 taken 94480836 times.
✓ Branch 1 taken 304 times.
94481140 if (MAPCOMBOFLAG2(layer, x, y) == flag)
3114 {
3115 304 found_cflag = true;
3116 304 break;
3117 }
3118 94480836 }
3119
3120
2/2
✓ Branch 0 taken 94482416 times.
✓ Branch 1 taken 13497488 times.
107979904 for (int32_t i=-1; i<6; i++) // Look for Trigger->Self on all layers
3121 {
3122
2/2
✓ Branch 0 taken 94467828 times.
✓ Branch 1 taken 14588 times.
94482416 if (found_nflag) // Trigger->Self (a.k.a Singular) is inherent
3123 {
3124
3/4
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 14476 times.
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
14588 if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE) && (MAPFLAG2(i, x, y) == flag))
3125 {
3126 112 rpos = COMBOPOS_REGION(x, y);
3127 112 }
3128
3/4
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 14424 times.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
14476 else if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE16) && (MAPFLAG2(i, x, y) == flag))
3129 {
3130 52 rpos = COMBOPOS_REGION(x, y);
3131 52 single16 = true;
3132 52 }
3133 14588 }
3134
3135
2/2
✓ Branch 0 taken 94480288 times.
✓ Branch 1 taken 2128 times.
94482416 if (found_cflag) // Trigger->Self (a.k.a Singular) is non-inherent
3136 {
3137
3/4
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 1873 times.
✓ Branch 2 taken 255 times.
✗ Branch 3 not taken.
2128 if ((MAPFLAG2(i, x, y) == mfSINGLE) && (MAPCOMBOFLAG2(i, x, y) == flag))
3138 {
3139 255 rpos = COMBOPOS_REGION(x, y);
3140 255 }
3141
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1853 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
1873 else if ((MAPFLAG2(i, x, y) == mfSINGLE16) && (MAPCOMBOFLAG2(i, x, y) == flag))
3142 {
3143 20 rpos = COMBOPOS_REGION(x, y);
3144 20 single16 = true;
3145 20 }
3146 2128 }
3147 94482416 }
3148
3149 13497488 out_rpos = rpos;
3150 13497488 out_single16 = single16;
3151
4/4
✓ Branch 0 taken 13495404 times.
✓ Branch 1 taken 2084 times.
✓ Branch 2 taken 13495102 times.
✓ Branch 3 taken 302 times.
13497488 return found_nflag || found_cflag || MAPFFCOMBOFLAG(x,y) == flag;
3152 13497488 }
3153
3154 4454376 bool trigger_secrets_if_flag(int32_t x, int32_t y, int32_t flag, bool setflag)
3155 {
3156
8/8
✓ Branch 0 taken 4454136 times.
✓ Branch 1 taken 240 times.
✓ Branch 2 taken 4452239 times.
✓ Branch 3 taken 1897 times.
✓ Branch 4 taken 4451719 times.
✓ Branch 5 taken 520 times.
✓ Branch 6 taken 952 times.
✓ Branch 7 taken 4450767 times.
4454376 if (x < -16 || y < -16 || x >= world_w || y >= world_h) return false;
3157
3158 4450767 mapscr* scr = NULL;
3159 4450767 int32_t screen = -1;
3160 4450767 rpos_t trigger_rpos = rpos_t::None;
3161 4450767 bool single16 = false;
3162
3163 4450767 std::vector<std::pair<int, int>> coords;
3164
1/2
✓ Branch 0 taken 4450767 times.
✗ Branch 1 not taken.
4450767 coords.push_back({x, y});
3165
1/2
✓ Branch 0 taken 4450767 times.
✗ Branch 1 not taken.
4450767 coords.push_back({x + 15, y});
3166
1/2
✓ Branch 0 taken 4450767 times.
✗ Branch 1 not taken.
4450767 coords.push_back({x, y + 15});
3167
1/2
✓ Branch 0 taken 4450767 times.
✗ Branch 1 not taken.
4450767 coords.push_back({x + 15, y + 15});
3168 4450767 std::vector<rpos_t> rposes_seen;
3169
2/2
✓ Branch 0 taken 4448370 times.
✓ Branch 1 taken 17797786 times.
84416752 for (auto [x, y] : coords)
3170 {
3171
2/4
✓ Branch 0 taken 17797786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17797786 times.
✗ Branch 3 not taken.
35595572 rpos_t rpos = COMBOPOS_REGION_B(x, y);
3172
2/2
✓ Branch 0 taken 17585413 times.
✓ Branch 1 taken 212373 times.
17797786 if (rpos == rpos_t::None)
3173 212373 continue;
3174
3175
4/6
✓ Branch 0 taken 17585413 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17585413 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 17585402 times.
35170826 if (MAPFFCOMBOFLAG(x, y) == flag)
3176 {
3177
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
22 screen = get_screen_for_world_xy(x, y);
3178 11 break;
3179 }
3180
3181 17585402 bool seen = false;
3182
2/2
✓ Branch 0 taken 13497488 times.
✓ Branch 1 taken 22110562 times.
35608050 for (rpos_t r : rposes_seen)
3183 {
3184
2/2
✓ Branch 0 taken 18022648 times.
✓ Branch 1 taken 4087914 times.
22110562 if (r == rpos)
3185 {
3186 4087914 seen = true;
3187 4087914 break;
3188 }
3189 }
3190
2/2
✓ Branch 0 taken 13497488 times.
✓ Branch 1 taken 4087914 times.
17585402 if (seen)
3191 4087914 continue;
3192
3193
1/2
✓ Branch 0 taken 13497488 times.
✗ Branch 1 not taken.
13497488 rposes_seen.push_back(rpos);
3194
4/6
✓ Branch 0 taken 13497488 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13497488 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2386 times.
✓ Branch 5 taken 13495102 times.
26994976 if (has_flag_trigger(x, y, flag, trigger_rpos, single16))
3195 {
3196
2/4
✓ Branch 0 taken 2386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2386 times.
✗ Branch 3 not taken.
4772 screen = get_screen_for_world_xy(x, y);
3197 2386 break;
3198 }
3199 }
3200
3201
3/4
✓ Branch 0 taken 2397 times.
✓ Branch 1 taken 4448370 times.
✓ Branch 2 taken 2397 times.
✗ Branch 3 not taken.
4450767 if (screen != -1) scr = get_scr(screen);
3202
2/2
✓ Branch 0 taken 2397 times.
✓ Branch 1 taken 4448370 times.
4450767 if (!scr) return false;
3203
3204
2/2
✓ Branch 0 taken 1958 times.
✓ Branch 1 taken 439 times.
2397 if (trigger_rpos == rpos_t::None)
3205 {
3206 1958 checktrigger = true;
3207
1/2
✓ Branch 0 taken 1958 times.
✗ Branch 1 not taken.
1958 trigger_secrets_for_screen(TriggerSource::Unspecified, screen);
3208 1958 }
3209 else
3210 {
3211 439 checktrigger = true;
3212
2/4
✓ Branch 0 taken 439 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 439 times.
✗ Branch 3 not taken.
439 trigger_secrets_for_screen(TriggerSource::Singular, scr, single16, RPOS_TO_POS(trigger_rpos));
3213 }
3214
3215
1/2
✓ Branch 0 taken 2397 times.
✗ Branch 1 not taken.
2397 sfx(scr->secretsfx);
3216
3217
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2391 times.
2397 if(scr->flags6&fTRIGGERFPERM)
3218 {
3219
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int32_t flags_remaining = findtrigger(screen); //Normal flags
3220
3221
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (flags_remaining)
3222 {
3223
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Z_eventlog("Hit All Triggers->Perm Secret not fulfilled (%d trigger flag%s remain).\n", flags_remaining, flags_remaining>1?"s":"");
3224 3 setflag=false;
3225 3 }
3226
3227 // Only actually trigger secrets now if 1) all triggers are gone and 2) QR qr_ALLTRIG_PERMSEC_NO_TEMP is off, in
3228 // which case only the screen state for mSECRET may be set below.
3229
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if (!flags_remaining && !get_qr(qr_ALLTRIG_PERMSEC_NO_TEMP))
3230 {
3231 trigger_secrets_for_screen(TriggerSource::Unspecified, scr, scr->flags6&fTRIGGERF1631, -1);
3232 }
3233 6 }
3234
3235
5/6
✓ Branch 0 taken 2292 times.
✓ Branch 1 taken 105 times.
✓ Branch 2 taken 2292 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1108 times.
✓ Branch 5 taken 1184 times.
2397 if (setflag && canPermSecret(cur_dmap, screen))
3236
2/2
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 463 times.
1905 if(!(scr->flags5&fTEMPSECRETS))
3237
1/2
✓ Branch 0 taken 721 times.
✗ Branch 1 not taken.
721 setmapflag(scr, mSECRET);
3238
3239 2397 return true;
3240 4454376 }
3241
3242 14812007 void update_slopes()
3243 {
3244
2/2
✓ Branch 0 taken 142356 times.
✓ Branch 1 taken 14812007 times.
14954363 for (auto& p : slopes)
3245 {
3246 142356 slope_object& s = p.second;
3247 142356 s.updateslope(); //sets old x/y poses
3248 }
3249 14812007 }
3250
3251 14405063 void update_freeform_combos()
3252 {
3253 14405063 ffscript_engine(false);
3254
2/2
✓ Branch 0 taken 24172 times.
✓ Branch 1 taken 14380891 times.
14405063 if ( !FFCore.system_suspend[susptUPDATEFFC] )
3255 {
3256 14380891 int wrap_right = world_w + 32;
3257 14380891 int wrap_bottom = world_h + 32;
3258
3259 485458561 for_every_ffc([&](const ffc_handle_t& ffc_handle) {
3260 471077670 mapscr* scr = ffc_handle.scr;
3261 471077670 ffcdata& thisffc = *ffc_handle.ffc;
3262
3263 // Combo 0?
3264
2/2
✓ Branch 0 taken 44992239 times.
✓ Branch 1 taken 426085431 times.
471077670 if(thisffc.data==0)
3265 426085431 return;
3266
3267 // Changer?
3268
2/2
✓ Branch 0 taken 543029 times.
✓ Branch 1 taken 44449210 times.
44992239 if(thisffc.flags&ffc_changer)
3269 543029 return;
3270
3271 // Stationary?
3272
2/2
✓ Branch 0 taken 9844 times.
✓ Branch 1 taken 44439366 times.
44449210 if(thisffc.flags&ffc_stationary)
3273 9844 return;
3274
3275 // Frozen because Hero's holding up an item?
3276
3/4
✓ Branch 0 taken 138282 times.
✓ Branch 1 taken 44301084 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138282 times.
44439366 if(Hero.getHoldClk()>0 && (thisffc.flags&ffc_ignoreholdup)==0)
3277 138282 return;
3278
3279 // Check for changers
3280
2/2
✓ Branch 0 taken 29543786 times.
✓ Branch 1 taken 14757298 times.
44301084 if (thisffc.link==0)
3281 {
3282 442453159 for_some_ffcs([&](const ffc_handle_t& other_ffc_handle) {
3283
2/2
✓ Branch 0 taken 14755762 times.
✓ Branch 1 taken 412940099 times.
427695861 if (ffc_handle.id == other_ffc_handle.id)
3284 14755762 return true;
3285
3286 412940099 ffcdata& otherffc = *other_ffc_handle.ffc;
3287 // Combo 0?
3288
2/2
✓ Branch 0 taken 144689583 times.
✓ Branch 1 taken 268250516 times.
412940099 if(otherffc.data==0)
3289 268250516 return true;
3290
3291 // Not a changer?
3292
2/2
✓ Branch 0 taken 140701406 times.
✓ Branch 1 taken 3988177 times.
144689583 if(!(otherffc.flags&ffc_changer))
3293 140701406 return true;
3294
3295 // Ignore this changer?
3296
4/4
✓ Branch 0 taken 546579 times.
✓ Branch 1 taken 3441598 times.
✓ Branch 2 taken 299257 times.
✓ Branch 3 taken 3142341 times.
3988177 if((otherffc.x.getInt()==thisffc.changer_x&&otherffc.y.getInt()==thisffc.changer_y) || thisffc.flags&ffc_ignorechanger)
3297 845836 return true;
3298
3299
3/4
✓ Branch 0 taken 2721043 times.
✓ Branch 1 taken 421298 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3562 times.
3145903 if((isonline(thisffc.x.getZLong(), thisffc.y.getZLong(), thisffc.prev_changer_x, thisffc.prev_changer_y, otherffc.x.getZLong(), otherffc.y.getZLong()) || // Along the line, or...
3300 ( // At exactly the same position,
3301
2/2
✓ Branch 0 taken 208792 times.
✓ Branch 1 taken 2512251 times.
2721043 (thisffc.x==otherffc.x && thisffc.y==otherffc.y))
3302
2/2
✓ Branch 0 taken 2303459 times.
✓ Branch 1 taken 2512251 times.
208792 ||
3303 //or imprecision and close enough
3304
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5024502 ( (thisffc.flags&ffc_imprecisionchanger) && ((abs(thisffc.x.getZLong() - otherffc.x.getZLong()) < 10000) && abs(thisffc.y.getZLong() - otherffc.y.getZLong()) < 10000) )
3305 )
3306 && //and...
3307
2/2
✓ Branch 0 taken 3562 times.
✓ Branch 1 taken 2721195 times.
2724757 (thisffc.prev_changer_x>-10000000 && thisffc.prev_changer_y>-10000000)) // This isn't the first frame on this screen
3308 {
3309 3562 zc_ffc_changer(thisffc, otherffc, ffc_handle.id, other_ffc_handle.id);
3310 3562 return false;
3311 }
3312
3313 2721195 return true;
3314 426679763 });
3315 14757298 }
3316
3317
2/2
✓ Branch 0 taken 29543786 times.
✓ Branch 1 taken 14757298 times.
44301084 ffcdata* linked_ffc = thisffc.link ? get_ffc_handle(thisffc.link - 1).ffc : nullptr;
3318
4/4
✓ Branch 0 taken 14757298 times.
✓ Branch 1 taken 29543786 times.
✓ Branch 2 taken 14680008 times.
✓ Branch 3 taken 14863778 times.
44301084 if (linked_ffc ? !linked_ffc->delay : !thisffc.delay)
3319 {
3320
4/4
✓ Branch 0 taken 182609 times.
✓ Branch 1 taken 14681169 times.
✓ Branch 2 taken 85331 times.
✓ Branch 3 taken 97278 times.
14863778 if(thisffc.link && (thisffc.link-1) != ffc_handle.id)
3321 {
3322 97278 thisffc.prev_changer_x = thisffc.x.getZLong();
3323 97278 thisffc.prev_changer_y = thisffc.y.getZLong();
3324 97278 thisffc.x += linked_ffc->vx;
3325 97278 thisffc.y += linked_ffc->vy;
3326 97278 }
3327 else
3328 {
3329 14766500 thisffc.prev_changer_x = thisffc.x.getZLong();
3330 14766500 thisffc.prev_changer_y = thisffc.y.getZLong();
3331 14766500 thisffc.x += thisffc.vx;
3332 14766500 thisffc.y += thisffc.vy;
3333 14766500 thisffc.vx += thisffc.ax;
3334 14766500 thisffc.vy += thisffc.ay;
3335
3336
3337
2/2
✓ Branch 0 taken 444046 times.
✓ Branch 1 taken 14322454 times.
14766500 if(get_qr(qr_OLD_FFC_SPEED_CAP))
3338 {
3339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vx>128) thisffc.vx=128;
3340
3341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vx<-128) thisffc.vx=-128;
3342
3343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vy>128) thisffc.vy=128;
3344
3345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vy<-128) thisffc.vy=-128;
3346 14322454 }
3347 }
3348 14863778 }
3349 else
3350 {
3351
3/4
✓ Branch 0 taken 1161 times.
✓ Branch 1 taken 76129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1161 times.
29437306 if(!thisffc.link || (thisffc.link-1) == ffc_handle.id)
3352 76129 thisffc.delay--;
3353 }
3354
3355 // Check if the FFC's off the side of the screen
3356
3357 // Left
3358
2/2
✓ Branch 0 taken 10449 times.
✓ Branch 1 taken 14930619 times.
14941068 if(thisffc.x<-32)
3359 {
3360
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 10196 times.
10449 if(scr->flags6&fWRAPAROUNDFF)
3361 {
3362 253 thisffc.x = wrap_right+(thisffc.x+32);
3363 253 thisffc.solid_update(false);
3364 253 thisffc.prev_changer_y = thisffc.y.getZLong();
3365 // Re-enable previous changer
3366 253 thisffc.changer_x = -1000;
3367 253 thisffc.changer_y = -1000;
3368 253 }
3369
2/2
✓ Branch 0 taken 10127 times.
✓ Branch 1 taken 69 times.
10196 else if(thisffc.x<-64)
3370 {
3371 69 zc_ffc_set(thisffc, 0);
3372 69 thisffc.flags&=~ffc_carryover;
3373 69 }
3374 10449 }
3375 // Right
3376
2/2
✓ Branch 0 taken 14930438 times.
✓ Branch 1 taken 181 times.
14930619 else if(thisffc.x>=wrap_right)
3377 {
3378
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 53 times.
181 if(scr->flags6&fWRAPAROUNDFF)
3379 {
3380 128 thisffc.x = thisffc.x-wrap_right-32;
3381 128 thisffc.solid_update(false);
3382 128 thisffc.prev_changer_y = thisffc.y.getZLong();
3383 128 thisffc.changer_x = -1000;
3384 128 thisffc.changer_y = -1000;
3385 128 }
3386 else
3387 {
3388 53 zc_ffc_set(thisffc, 0);
3389 53 thisffc.flags&=~ffc_carryover;
3390 }
3391 181 }
3392
3393 // Top
3394
2/2
✓ Branch 0 taken 25480 times.
✓ Branch 1 taken 14915588 times.
14941068 if(thisffc.y<-32)
3395 {
3396
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 25472 times.
25480 if(scr->flags6&fWRAPAROUNDFF)
3397 {
3398 8 thisffc.y = wrap_bottom+(thisffc.y+32);
3399 8 thisffc.solid_update(false);
3400 8 thisffc.prev_changer_x = thisffc.x.getZLong();
3401 8 thisffc.changer_x = -1000;
3402 8 thisffc.changer_y = -1000;
3403 8 }
3404
2/2
✓ Branch 0 taken 25155 times.
✓ Branch 1 taken 317 times.
25472 else if(thisffc.y<-64)
3405 {
3406 317 zc_ffc_set(thisffc, 0);
3407 317 thisffc.flags&=~ffc_carryover;
3408 317 }
3409 25480 }
3410 // Bottom
3411
2/2
✓ Branch 0 taken 14914744 times.
✓ Branch 1 taken 844 times.
14915588 else if(thisffc.y>=wrap_bottom)
3412 {
3413
2/2
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 91 times.
844 if(scr->flags6&fWRAPAROUNDFF)
3414 {
3415 753 thisffc.y = thisffc.y-wrap_bottom-32;
3416 753 thisffc.solid_update(false);
3417 753 thisffc.prev_changer_y = thisffc.x.getZLong();
3418 753 thisffc.changer_x = -1000;
3419 753 thisffc.changer_y = -1000;
3420 753 }
3421 else
3422 {
3423 91 zc_ffc_set(thisffc, 0);
3424 91 thisffc.flags&=~ffc_carryover;
3425 }
3426 844 }
3427 14941068 thisffc.solid_update();
3428 441717654 });
3429 14380891 }
3430 14405063 }
3431
3432 2098420 bool hitcombo(int32_t x, int32_t y, int32_t combotype, byte layers)
3433 {
3434
2/2
✓ Branch 0 taken 14685796 times.
✓ Branch 1 taken 2097896 times.
16783692 for(int q = 0; q < 7; ++q)
3435 {
3436
2/2
✓ Branch 0 taken 12587376 times.
✓ Branch 1 taken 2098420 times.
14685796 if(layers&(1<<q)) //if layer is to be checked
3437
2/2
✓ Branch 0 taken 2097896 times.
✓ Branch 1 taken 524 times.
2098420 if(COMBOTYPE2(q-1,x,y)==combotype) //matching type
3438 524 return true;
3439 14685272 }
3440 2097896 return false;
3441 2098420 }
3442
3443 419684 int gethitcombo(int32_t x, int32_t y, int32_t combotype, byte layers)
3444 {
3445
2/2
✓ Branch 0 taken 2937788 times.
✓ Branch 1 taken 419684 times.
3357472 for(int q = 0; q < 7; ++q)
3446 {
3447
2/2
✓ Branch 0 taken 2518104 times.
✓ Branch 1 taken 419684 times.
2937788 if(layers&(1<<q)) //if layer is to be checked
3448
1/2
✓ Branch 0 taken 419684 times.
✗ Branch 1 not taken.
419684 if(COMBOTYPE2(q-1,x,y)==combotype) //matching type
3449 return MAPCOMBO2(q-1,x,y);
3450 2937788 }
3451 419684 return -1;
3452 419684 }
3453
3454 bool hitflag(int32_t x, int32_t y, int32_t flagtype, byte layers)
3455 {
3456 for(int q = 0; q < 7; ++q)
3457 {
3458 if(layers&(1<<q)) //if layer is to be checked
3459 if(MAPFLAG2(q-1,x,y)==flagtype||MAPCOMBOFLAG2(q-1,x,y)==flagtype) //matching flag
3460 return true;
3461 }
3462 return false;
3463 }
3464
3465 231 optional<int> nextscr(int screen, int dir)
3466 {
3467 231 auto [m, s] = nextscr2(cur_map, screen, dir);
3468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
231 if (m == -1) return nullopt;
3469 462 return (m<<7) + s;
3470 231 }
3471
3472 1058 std::pair<int32_t, int32_t> nextscr2(int32_t dir)
3473 {
3474 1058 int32_t map = cur_map;
3475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 int32_t screen = screenscrolling ? scrolling_hero_screen : hero_screen;
3476 1058 return nextscr2(map, screen, dir);
3477 }
3478
3479 5570 std::pair<int32_t, int32_t> nextscr2(int map, int screen, int32_t dir)
3480 {
3481 5570 screen = screen_index_direction(screen, (direction)dir);
3482
3483 // need to check for screens on other maps, 's' not valid, etc.
3484 5570 int32_t index = (hero_scr->sidewarpindex >> (dir*2))&3;
3485
3486 // Fun fact: when a scrolling warp is triggered, this function
3487 // is never even called! - Saf
3488
2/2
✓ Branch 0 taken 3322 times.
✓ Branch 1 taken 2248 times.
6114 if(hero_scr->sidewarptype[index] == 3) // scrolling warp
3489 {
3490
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 482 times.
✓ Branch 2 taken 525 times.
✓ Branch 3 taken 545 times.
✓ Branch 4 taken 696 times.
2248 switch(dir)
3491 {
3492 case up:
3493
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 399 times.
482 if(!(hero_scr->flags2&wfUP)) goto nowarp;
3494
3495 83 break;
3496
3497 case down:
3498
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 446 times.
525 if(!(hero_scr->flags2&wfDOWN)) goto nowarp;
3499
3500 79 break;
3501
3502 case left:
3503
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 336 times.
545 if(!(hero_scr->flags2&wfLEFT)) goto nowarp;
3504
3505 209 break;
3506
3507 case right:
3508
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 523 times.
696 if(!(hero_scr->flags2&wfRIGHT)) goto nowarp;
3509
3510 173 break;
3511 }
3512
3513 544 map = DMaps[hero_scr->sidewarpdmap[index]].map;
3514 544 screen = hero_scr->sidewarpscr[index] + DMaps[hero_scr->sidewarpdmap[index]].xoff;
3515 544 }
3516
3517 nowarp:
3518
4/4
✓ Branch 0 taken 5506 times.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 5394 times.
5570 if(screen<0||screen>=128)
3519 176 return {-1, -1};
3520
3521 5394 return {map, screen};
3522 5570 }
3523
3524 401 optional<int> nextscr_mi(int mi, int dir)
3525 {
3526 401 int map = mi/MAPSCRSNORMAL;
3527 401 int screen = mi%MAPSCRSNORMAL;
3528 401 auto [m, s] = nextscr2(map, screen, dir);
3529
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 400 times.
401 if (m == -1) return nullopt;
3530 800 return (m<<7) + s;
3531 401 }
3532
3533 2113 void bombdoor(int32_t x,int32_t y)
3534 {
3535
2/2
✓ Branch 0 taken 2093 times.
✓ Branch 1 taken 20 times.
2113 if (!is_in_world_bounds(x, y))
3536 20 return;
3537
3538 2093 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
3539 2093 mapscr* scr = rpos_handle.scr;
3540 2093 int screen = scr->screen;
3541 2901 auto [x0, y0] = translate_screen_coordinates_to_world(rpos_handle.screen);
3542 #define CHECK_RECT(x,y,rx1,ry1,rx2,ry2) (isinRect(x,y,x0+rx1,y0+ry1,x0+rx2,y0+ry2))
3543
3544
12/12
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 2014 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 69 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 69 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 69 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 69 times.
2093 if(scr->door[0]==dBOMB && CHECK_RECT(x,y,100,0,139,48))
3545 {
3546 69 scr->door[0]=dBOMBED;
3547 69 putdoor(scr, scrollbuf, 0, dBOMBED);
3548 69 setmapflag(scr, mDOOR_UP);
3549 69 markBmap(-1, screen);
3550
3551
1/2
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
69 if(auto v = nextscr(screen, up))
3552 {
3553 69 setmapflag_mi(*v, mDOOR_DOWN);
3554 69 markBmap(-1,*v-(get_currdmap()<<7));
3555 69 }
3556 69 }
3557
3558
12/12
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 2044 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 39 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 39 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 39 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 39 times.
2093 if(scr->door[1]==dBOMB && CHECK_RECT(x,y,100,112,139,176))
3559 {
3560 39 scr->door[1]=dBOMBED;
3561 39 putdoor(scr, scrollbuf, 1, dBOMBED);
3562 39 setmapflag(scr, mDOOR_DOWN);
3563 39 markBmap(-1, rpos_handle.screen);
3564
3565
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if(auto v = nextscr(rpos_handle.screen, down))
3566 {
3567 39 setmapflag_mi(*v, mDOOR_UP);
3568 39 markBmap(-1,*v-(get_currdmap()<<7));
3569 39 }
3570 39 }
3571
3572
12/12
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 2026 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 51 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 51 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 51 times.
✓ Branch 8 taken 16 times.
✓ Branch 9 taken 51 times.
✓ Branch 10 taken 16 times.
✓ Branch 11 taken 51 times.
2093 if(scr->door[2]==dBOMB && CHECK_RECT(x,y,0,60,48,98))
3573 {
3574 51 scr->door[2]=dBOMBED;
3575 51 putdoor(scr, scrollbuf, 2, dBOMBED);
3576 51 setmapflag(scr, mDOOR_LEFT);
3577 51 markBmap(-1, rpos_handle.screen);
3578
3579
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(auto v = nextscr(rpos_handle.screen, left))
3580 {
3581 51 setmapflag_mi(*v, mDOOR_RIGHT);
3582 51 markBmap(-1,*v-(get_currdmap()<<7));
3583 51 }
3584 51 }
3585
3586
12/12
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 2007 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 72 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 72 times.
✓ Branch 8 taken 14 times.
✓ Branch 9 taken 72 times.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 72 times.
2093 if(scr->door[3]==dBOMB && CHECK_RECT(x,y,192,60,240,98))
3587 {
3588 72 scr->door[3]=dBOMBED;
3589 72 putdoor(scr, scrollbuf, 3, dBOMBED);
3590 72 setmapflag(scr, mDOOR_RIGHT);
3591 72 markBmap(-1, rpos_handle.screen);
3592
3593
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(auto v = nextscr(rpos_handle.screen, right))
3594 {
3595 72 setmapflag_mi(*v, mDOOR_LEFT);
3596 72 markBmap(-1,*v-(get_currdmap()<<7));
3597 72 }
3598 72 }
3599 2113 }
3600
3601 6387775623 void draw_cmb(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset,
3602 bool over, bool transp)
3603 {
3604 6387775623 auto& cmb = combobuf[cid];
3605
2/2
✓ Branch 0 taken 318783 times.
✓ Branch 1 taken 6387456840 times.
6387775623 if(cmb.animflags & AF_EDITOR_ONLY)
3606 318783 return;
3607
2/2
✓ Branch 0 taken 3312116374 times.
✓ Branch 1 taken 3075340466 times.
6387456840 if(over)
3608 {
3609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3312116374 times.
3312116374 if(cmb.animflags & AF_TRANSPARENT)
3610 transp = !transp;
3611
2/2
✓ Branch 0 taken 319148412 times.
✓ Branch 1 taken 2992967962 times.
3312116374 if(transp)
3612 319148412 overcombotranslucent(dest, x, y, cid, cset, 128);
3613 2992967962 else overcombo(dest, x, y, cid, cset);
3614 3312116374 }
3615 3075340466 else putcombo(dest, x, y, cid, cset);
3616 6387775623 }
3617 6387784071 void draw_cmb_pos(BITMAP* dest, int32_t x, int32_t y, rpos_t rpos, int32_t cid,
3618 int32_t cset, byte layer, bool over, bool transp)
3619 {
3620
2/2
✓ Branch 0 taken 751168571 times.
✓ Branch 1 taken 5636615500 times.
6387784071 if (rpos != rpos_t::None)
3621 {
3622 5636615500 rpos_t plrpos = COMBOPOS_REGION_B(Hero.x+8, Hero.y+8);
3623
2/2
✓ Branch 0 taken 749524 times.
✓ Branch 1 taken 5635865976 times.
5636615500 if (plrpos != rpos_t::None)
3624 {
3625 5635865976 bool dosw = false;
3626
4/4
✓ Branch 0 taken 52860 times.
✓ Branch 1 taken 5635813116 times.
✓ Branch 2 taken 44412 times.
✓ Branch 3 taken 8448 times.
5635865976 if (rpos == hooked_comborpos && (hooked_layerbits & (1<<layer)))
3627 {
3628
1/2
✓ Branch 0 taken 8448 times.
✗ Branch 1 not taken.
8448 if(hooked_undercombos[layer] > -1)
3629 {
3630 draw_cmb(dest, x, y,
3631 hooked_undercombos[layer], hooked_undercombos[layer+7], over, transp);
3632 }
3633 8448 dosw = true;
3634 8448 }
3635
4/4
✓ Branch 0 taken 31991064 times.
✓ Branch 1 taken 5603866464 times.
✓ Branch 2 taken 8448 times.
✓ Branch 3 taken 31982616 times.
5635857528 else if (rpos == plrpos && (hooked_layerbits & (1<<(layer+8))))
3636 {
3637 8448 dosw = true;
3638 8448 }
3639
2/2
✓ Branch 0 taken 5635849080 times.
✓ Branch 1 taken 16896 times.
5635865976 if (dosw)
3640 {
3641
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 16896 times.
✗ Branch 3 not taken.
16896 switch (Hero.switchhookstyle)
3642 {
3643 default: case swPOOF:
3644 break; //Nothing special here
3645 case swFLICKER:
3646 {
3647
2/2
✓ Branch 0 taken 8448 times.
✓ Branch 1 taken 8448 times.
16896 if(abs(Hero.switchhookclk-33)&0b1000)
3648 8448 break; //Drawn this frame
3649 8448 return; //Not drawn this frame
3650 }
3651 case swRISE:
3652 {
3653 //Draw rising up
3654 y -= 8-(abs(Hero.switchhookclk-32)/4);
3655 break;
3656 }
3657 }
3658 8448 }
3659 5635857528 }
3660 5636607052 }
3661
3662 6387775623 draw_cmb(dest, x, y, cid, cset, over, transp);
3663 6387784071 }
3664
3665 // `draw_cmb_pos` only does meaningful work if the combo being drawn is within the bounds of
3666 // the `bmp` bitmap. However, even getting to the point where `puttile16` (for example) knows
3667 // to cull is somewhat expensive. Since it can only draw 16x16 pixels, we can do the equivalent
3668 // culling here by determining the rows/columns that are within the bitmap bounds. This nets
3669 // on the order of ~30 FPS in uncapped mode on my machine, depending on the viewport/region size.
3670 //
3671 // These two inequalities must be true for `draw_cmb_pos` to do anything useful:
3672 //
3673 // -16 < comboPositionX*16 + x < bitmapWidth
3674 // -16 < comboPositionY*16 + y < bitmapHeight
3675 //
3676 // The following start/end values are derived directly from the above.
3677 //
3678 // `x` and `y` are the offsets the combos will be drawn into the bitmap.
3679 39504207 static void get_bounds_for_draw_cmb_calls(BITMAP* bmp, int x, int y, int& start_x, int& end_x, int& start_y, int& end_y)
3680 {
3681 // if (bmp->clip)
3682 // {
3683 // start_x = MAX(0, ceil((bmp->cl - 15 - x) / 16.0));
3684 // end_x = MIN(16, ceil((bmp->cr - x) / 16.0));
3685 // start_y = MAX(0, ceil((bmp->ct - 15 - y) / 16.0));
3686 // end_y = MIN(11, ceil((bmp->cb - y) / 16.0));
3687 // return;
3688 // }
3689
3690
2/2
✓ Branch 0 taken 2172666 times.
✓ Branch 1 taken 37331541 times.
39504207 start_x = MAX(0, ceil((-15 - x) / 16.0));
3691
2/2
✓ Branch 0 taken 2181853 times.
✓ Branch 1 taken 37322354 times.
39504207 end_x = MIN(16, ceil((bmp->w - x) / 16.0));
3692
2/2
✓ Branch 0 taken 38115557 times.
✓ Branch 1 taken 1388650 times.
39504207 start_y = MAX(0, ceil((-15 - y) / 16.0));
3693
2/2
✓ Branch 0 taken 1677783 times.
✓ Branch 1 taken 37826424 times.
39504207 end_y = MIN(11, ceil((bmp->h - y) / 16.0));
3694 39504207 }
3695
3696 186999371 void do_ffc_layer(BITMAP* bmp, int32_t layer, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3697 {
3698
1/2
✓ Branch 0 taken 186999371 times.
✗ Branch 1 not taken.
186999371 if(!show_ffcs) return;
3699 186999371 mapscr* scr = screen_handle.scr;
3700 186999371 mapscr* base_scr = screen_handle.base_scr;
3701
3702 186999371 y += playing_field_offset;
3703
3704 186999371 bool is_bg_layer = layer < -1;
3705
2/2
✓ Branch 0 taken 33933637 times.
✓ Branch 1 taken 153065734 times.
186999371 int real_layer = is_bg_layer ? abs(layer) : layer;
3706
2/2
✓ Branch 0 taken 186999371 times.
✓ Branch 1 taken 5580339704 times.
5767339075 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3707 {
3708
2/2
✓ Branch 0 taken 5374842008 times.
✓ Branch 1 taken 205497696 times.
5580339704 if (base_scr->ffcs[i].data == 0)
3709 5374842008 continue;
3710
4/4
✓ Branch 0 taken 37360962 times.
✓ Branch 1 taken 168136734 times.
✓ Branch 2 taken 18682962 times.
✓ Branch 3 taken 18678000 times.
205497696 if(real_layer == 2 && (is_bg_layer != XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)))
3711 18678000 continue;
3712
4/4
✓ Branch 0 taken 37360962 times.
✓ Branch 1 taken 149458734 times.
✓ Branch 2 taken 18682962 times.
✓ Branch 3 taken 18678000 times.
186819696 else if (real_layer == 3 && (is_bg_layer != XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)))
3713 18678000 continue;
3714
4/4
✓ Branch 0 taken 149463696 times.
✓ Branch 1 taken 18678000 times.
✓ Branch 2 taken 18682962 times.
✓ Branch 3 taken 130780734 times.
168141696 if (real_layer > -1 && base_scr->ffcs[i].layer != real_layer)
3715 130780734 continue;
3716
3717
6/6
✓ Branch 0 taken 3008970 times.
✓ Branch 1 taken 34351992 times.
✓ Branch 2 taken 5110 times.
✓ Branch 3 taken 3003860 times.
✓ Branch 4 taken 2626 times.
✓ Branch 5 taken 2484 times.
37360962 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3718 2484 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3719
3720 37358478 base_scr->ffcs[i].draw_ffc(bmp, x, y, (layer==-1));
3721 37358478 }
3722 186999371 }
3723 170961791 void _do_current_ffc_layer(BITMAP* bmp, int32_t layer)
3724 {
3725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 170961791 times.
170961791 if(!show_ffcs) return;
3726 346501804 for_every_base_screen_in_region([&](mapscr* base_scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3727 175540013 screen_handle_t handle = {base_scr, base_scr, base_scr->screen, 0};
3728 175540013 do_ffc_layer(bmp, layer, handle, 0, 0);
3729 175540013 });
3730 170961791 }
3731 74516097 void do_scrolling_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3732 {
3733 74516097 mapscr* scr = screen_handle.scr;
3734 74516097 mapscr* base_scr = screen_handle.base_scr;
3735
3736
4/4
✓ Branch 0 taken 60983599 times.
✓ Branch 1 taken 13532498 times.
✓ Branch 2 taken 13532498 times.
✓ Branch 3 taken 74516097 times.
74516097 if (type == -3 || type == -4)
3737 {
3738 27064996 y += playing_field_offset;
3739
3740
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
27064996 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3741 {
3742 if (base_scr->ffcs[i].data == 0)
3743 continue;
3744
3745 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3746 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3747
3748 base_scr->ffcs[i].draw_ffc(bmp, x, y, (type==-4));
3749 }
3750 return;
3751 }
3752
3753 74516097 x -= viewport.x;
3754 74516097 y -= viewport.y - playing_field_offset;
3755
3756 74516097 bool over = true, transp = false;
3757 74516097 int layer = screen_handle.layer;
3758
3759
7/8
✓ Branch 0 taken 54031281 times.
✓ Branch 1 taken 20484816 times.
✓ Branch 2 taken 13155050 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33049442 times.
✓ Branch 5 taken 20981839 times.
✓ Branch 6 taken 3066358 times.
✓ Branch 7 taken 4263408 times.
74516097 switch(type ? type : layer)
3760 {
3761 case -2: //push blocks
3762
2/2
✓ Branch 0 taken 19516944 times.
✓ Branch 1 taken 13532498 times.
33049442 if (scr)
3763 {
3764
2/2
✓ Branch 0 taken 3434982144 times.
✓ Branch 1 taken 23174542 times.
3431716248 for(int32_t i=0; i<176; i++)
3765 {
3766 3434982144 int32_t mf=scr->sflag[i], mf2 = combobuf[scr->data[i]].flag;
3767
3768
10/10
✓ Branch 0 taken 3434811800 times.
✓ Branch 1 taken 170344 times.
✓ Branch 2 taken 3433339828 times.
✓ Branch 3 taken 1471972 times.
✓ Branch 4 taken 3432710845 times.
✓ Branch 5 taken 628983 times.
✓ Branch 6 taken 24420876 times.
✓ Branch 7 taken 3408289969 times.
✓ Branch 8 taken 42763031 times.
✓ Branch 9 taken 13948967 times.
3472029612 if(mf==mfPUSHUD || mf==mfPUSH4 || mf==mfPUSHED || ((mf>=mfPUSHLR)&&(mf<=mfPUSHRINS))
3769
6/8
✓ Branch 0 taken 3429829315 times.
✓ Branch 1 taken 21539346 times.
✓ Branch 2 taken 3429829315 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3429829315 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 37047468 times.
✓ Branch 7 taken 3392781847 times.
3432710845 || mf2==mfPUSHUD || mf2==mfPUSH4 || mf2==mfPUSHED || ((mf2>=mfPUSHLR)&&(mf2<=mfPUSHRINS)))
3770 {
3771
4/4
✓ Branch 0 taken 4772508 times.
✓ Branch 1 taken 695982 times.
✓ Branch 2 taken 3657 times.
✓ Branch 3 taken 4768851 times.
90994552 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3772 5468490 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3773 5468490 }
3774 3412199304 }
3775 23174542 }
3776 36707040 return;
3777
3778 case -1: //over combo
3779
1/2
✓ Branch 0 taken 20981839 times.
✗ Branch 1 not taken.
20981839 if (scr)
3780 {
3781
2/2
✓ Branch 0 taken 3692803664 times.
✓ Branch 1 taken 20981839 times.
3713785503 for(int32_t i=0; i<176; i++)
3782 {
3783
2/2
✓ Branch 0 taken 3673533516 times.
✓ Branch 1 taken 19270148 times.
3692803664 if(combo_class_buf[combobuf[scr->data[i]].type].overhead)
3784 {
3785
4/4
✓ Branch 0 taken 15517569 times.
✓ Branch 1 taken 3752579 times.
✓ Branch 2 taken 22320 times.
✓ Branch 3 taken 15495249 times.
19270148 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3786 19270148 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3787 19270148 }
3788 3692803664 }
3789 20981839 }
3790 20981839 return;
3791
3792 case 1:
3793 case 4:
3794 case 5:
3795 case 6:
3796
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13155050 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
13155050 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3797 {
3798
1/2
✓ Branch 0 taken 13155050 times.
✗ Branch 1 not taken.
13155050 if (scr)
3799 {
3800
2/2
✓ Branch 0 taken 11495839 times.
✓ Branch 1 taken 1659211 times.
13155050 if(base_scr->layeropacity[layer-1]!=255)
3801 1659211 transp = true;
3802 13155050 break;
3803 }
3804 }
3805 return;
3806
3807 case 2:
3808
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3066358 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3066358 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3809 {
3810
1/2
✓ Branch 0 taken 3066358 times.
✗ Branch 1 not taken.
3066358 if (scr)
3811 {
3812
2/2
✓ Branch 0 taken 2846761 times.
✓ Branch 1 taken 219597 times.
3066358 if(base_scr->layeropacity[layer-1]!=255)
3813 219597 transp = true;
3814
3815
2/2
✓ Branch 0 taken 2937448 times.
✓ Branch 1 taken 128910 times.
3066358 if(XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3816 128910 over = false;
3817
3818 3066358 break;
3819 }
3820 }
3821 return;
3822
3823 case 3:
3824
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4263408 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4263408 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3825 {
3826
1/2
✓ Branch 0 taken 4263408 times.
✗ Branch 1 not taken.
4263408 if (scr)
3827 {
3828
2/2
✓ Branch 0 taken 4189695 times.
✓ Branch 1 taken 73713 times.
4263408 if(base_scr->layeropacity[layer-1]!=255)
3829 73713 transp = true;
3830
3831
2/2
✓ Branch 0 taken 36655 times.
✓ Branch 1 taken 60483 times.
4263408 if(XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)
3832
2/2
✓ Branch 0 taken 97138 times.
✓ Branch 1 taken 4166270 times.
4263408 && !XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3833 60483 over = false;
3834
3835 4263408 break;
3836 }
3837 }
3838 return;
3839 }
3840
3841 int start_x, end_x, start_y, end_y;
3842 20484816 get_bounds_for_draw_cmb_calls(bmp, x, y, start_x, end_x, start_y, end_y);
3843
2/2
✓ Branch 0 taken 20484816 times.
✓ Branch 1 taken 217204074 times.
237688890 for (int cy = start_y; cy < end_y; cy++)
3844 {
3845
2/2
✓ Branch 0 taken 3286730935 times.
✓ Branch 1 taken 217204074 times.
3503935009 for (int cx = start_x; cx < end_x; cx++)
3846 {
3847 3286730935 int i = cx + cy*16;
3848
4/4
✓ Branch 0 taken 2908202636 times.
✓ Branch 1 taken 378528299 times.
✓ Branch 2 taken 10227360 times.
✓ Branch 3 taken 2897975276 times.
3286730935 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3849 3286730935 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, over, transp);
3850 3286730935 }
3851 217204074 }
3852 60983599 }
3853
3854 269047266 bool lenscheck(mapscr* scr, int layer)
3855 {
3856
4/4
✓ Branch 0 taken 268868318 times.
✓ Branch 1 taken 178948 times.
✓ Branch 2 taken 178948 times.
✓ Branch 3 taken 269047266 times.
269047266 if(layer < 0 || layer > 6) return true;
3857
2/2
✓ Branch 0 taken 259544331 times.
✓ Branch 1 taken 9502935 times.
269047266 if(get_qr(qr_OLD_LENS_LAYEREFFECT))
3858 {
3859
2/2
✓ Branch 0 taken 209674915 times.
✓ Branch 1 taken 49869416 times.
259544331 if(!layer) return true;
3860
8/8
✓ Branch 0 taken 34916446 times.
✓ Branch 1 taken 174758469 times.
✓ Branch 2 taken 258970 times.
✓ Branch 3 taken 34657476 times.
✓ Branch 4 taken 143758 times.
✓ Branch 5 taken 163336 times.
✓ Branch 6 taken 326536 times.
✓ Branch 7 taken 34474698 times.
209674915 if((layer==(int32_t)(scr->lens_layer&7)+1) && ((scr->lens_layer&llLENSSHOWS && !lensclk) || (scr->lens_layer&llLENSHIDES && lensclk)))
3861 489872 return false;
3862 209233167 }
3863 else
3864 {
3865
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9502935 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9502935 times.
9502935 if((lensclk ? scr->lens_hide : scr->lens_show) & (1<<layer))
3866 return false;
3867 }
3868 218736102 return true;
3869 268868318 }
3870
3871 156189675 void do_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3872 {
3873 156189675 bool showlayer = true;
3874 156189675 mapscr* base_scr = screen_handle.base_scr;
3875 156189675 int layer = screen_handle.layer;
3876
2/2
✓ Branch 0 taken 42095865 times.
✓ Branch 1 taken 114093810 times.
156189675 int target = type ? type : layer;
3877
3/4
✓ Branch 0 taken 114093810 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20227168 times.
✓ Branch 3 taken 21868697 times.
156189675 switch(target)
3878 {
3879 case -2:
3880
1/2
✓ Branch 0 taken 20227168 times.
✗ Branch 1 not taken.
20227168 if(!show_layer_push)
3881 showlayer = false;
3882 20227168 break;
3883
3884 case -1:
3885
1/2
✓ Branch 0 taken 21868697 times.
✗ Branch 1 not taken.
21868697 if(!show_layer_over)
3886 showlayer = false;
3887 21868697 break;
3888
3889 case 1: case 2: case 3:
3890 case 4: case 5: case 6:
3891 114093810 showlayer = show_layers[target];
3892 114093810 break;
3893 }
3894
3895
2/2
✓ Branch 0 taken 42095865 times.
✓ Branch 1 taken 114093810 times.
156189675 if(!type)
3896 {
3897
2/2
✓ Branch 0 taken 113957612 times.
✓ Branch 1 taken 136198 times.
114093810 if(!lenscheck(base_scr,layer))
3898 136198 showlayer = false;
3899 114093810 }
3900
3901
2/2
✓ Branch 0 taken 136198 times.
✓ Branch 1 taken 156053477 times.
156189675 if(showlayer)
3902 {
3903
6/6
✓ Branch 0 taken 61039722 times.
✓ Branch 1 taken 95013755 times.
✓ Branch 2 taken 20540939 times.
✓ Branch 3 taken 40498783 times.
✓ Branch 4 taken 56123 times.
✓ Branch 5 taken 20484816 times.
156053477 if (screen_handle.scr && (type || !(base_scr->hidelayers & (1 << (layer)))))
3904 {
3905 60983599 do_scrolling_layer(bmp, type, screen_handle, x, y);
3906
4/4
✓ Branch 0 taken 20484816 times.
✓ Branch 1 taken 40498783 times.
✓ Branch 2 taken 19233766 times.
✓ Branch 3 taken 1251050 times.
60983599 if(!type && !get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3907
2/2
✓ Branch 0 taken 1250474 times.
✓ Branch 1 taken 576 times.
1251626 if(mblock2.draw(bmp,layer))
3908 576 do_primitives(bmp, SPLAYER_MOVINGBLOCK);
3909 60983599 }
3910 156053477 }
3911 156189675 }
3912
3913 103042095 void do_layer_primitives(BITMAP *bmp, int32_t layer)
3914 {
3915 103042095 bool showlayer = true;
3916
3917
2/4
✓ Branch 0 taken 103042095 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 103042095 times.
103042095 if(layer >= 0 && layer <= 6)
3918 {
3919 103042095 showlayer = show_layers[layer];
3920
3921
2/2
✓ Branch 0 taken 102915493 times.
✓ Branch 1 taken 126602 times.
103042095 if(!lenscheck(origin_scr,layer))
3922 126602 showlayer = false;
3923 103042095 }
3924
3925
2/2
✓ Branch 0 taken 126602 times.
✓ Branch 1 taken 102915493 times.
103042095 if (showlayer)
3926 102915493 do_primitives(bmp, layer);
3927 103042095 }
3928
3929 // Called by do_walkflags
3930 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
3931 {
3932 newcombo const &c = combobuf[cmbdat];
3933
3934 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
3935
3936 int32_t xx = x-xofs;
3937 int32_t yy = y+playing_field_offset-yofs;
3938
3939 int32_t bridgedetected = 0;
3940
3941 for(int32_t i=0; i<4; i++)
3942 {
3943 int32_t tx=((i&2)<<2)+xx - viewport.x;
3944 int32_t ty=((i&1)<<3)+yy - viewport.y;
3945 int32_t tx2=((i&2)<<2)+x - viewport.x;
3946 int32_t ty2=((i&1)<<3)+y - viewport.y;
3947 for (int32_t j = lyr-1; j <= 1; j++)
3948 {
3949 if (get_qr(qr_OLD_BRIDGE_COMBOS))
3950 {
3951 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && !_walkflag_layer(tx2,ty2,j))
3952 {
3953 bridgedetected |= (1<<i);
3954 }
3955 }
3956 else
3957 {
3958 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && _effectflag_layer(tx2,ty2,j))
3959 {
3960 bridgedetected |= (1<<i);
3961 }
3962 }
3963 }
3964 if ((bridgedetected & (1<<i)))
3965 {
3966 if (i >= 3) break;
3967 else continue;
3968 }
3969 bool doladdercheck = true;
3970
3971 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
3972 {
3973 for(int32_t k=0; k<8; k+=2)
3974 for(int32_t j=0; j<8; j+=2)
3975 if(((k+j)/2)%2)
3976 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,makecol(85,85,255));
3977 }
3978 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
3979 {
3980 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
3981 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
3982 rectfill(dest,tx,ty,tx+7,ty+7,makecol(85,85,255));
3983 else rectfill(dest,tx,ty,tx+7,ty+7,makecol(170,170,170));
3984 }
3985
3986 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
3987 {
3988 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
3989 {
3990 for(int32_t k=0; k<8; k+=2)
3991 for(int32_t j=0; j<8; j+=2)
3992 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,((k+j)/2)%2 ? makecol(165,105,8) : makecol(170,170,170));
3993 }
3994 else
3995 {
3996 int32_t color = makecol(178,36,36);
3997
3998 if(isstepable(cmbdat)&& (!doladdercheck))
3999 color=makecol(165,105,8);
4000 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4001 color=makecol(170,170,170);
4002
4003 rectfill(dest,tx,ty,tx+7,ty+7,color);
4004 }
4005 }
4006 }
4007
4008 // Draw damage combos
4009 bool dmg = combo_class_buf[combobuf[MAPCOMBO2(-1,xx,yy)].type].modify_hp_amount
4010 || combo_class_buf[combobuf[MAPCOMBO2(0,xx,yy)].type].modify_hp_amount
4011 || combo_class_buf[combobuf[MAPCOMBO2(1,xx,yy)].type].modify_hp_amount;
4012
4013 if(dmg)
4014 {
4015 int32_t color = makecol(255,255,0);
4016 if (bridgedetected <= 0)
4017 {
4018 for(int32_t k=0; k<16; k+=2)
4019 for(int32_t j=0; j<16; j+=2)
4020 if(((k+j)/2)%2)
4021 {
4022 int32_t x0 = x - viewport.x;
4023 int32_t y0 = y - viewport.y;
4024 rectfill(dest,x0+k,y0+j,x0+k+1,y0+j+1,color);
4025 }
4026 }
4027 else
4028 {
4029 for(int32_t i=0; i<4; i++)
4030 {
4031 if (!(bridgedetected & (1<<i)))
4032 {
4033 int32_t tx=((i&2)<<2)+x - viewport.x;
4034 int32_t ty=((i&1)<<3)+y - viewport.y;
4035 for(int32_t k=0; k<8; k+=2)
4036 for(int32_t j=0; j<8; j+=2)
4037 if((k+j)%4 < 2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,color);
4038 }
4039 }
4040 }
4041 }
4042 }
4043 static void put_walkflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4044 {
4045 ALLEGRO_COLOR col_solid = al_map_rgba(178,36,36,info_opacity);
4046 ALLEGRO_COLOR col_water1 = al_map_rgba(85,85,255,info_opacity);
4047 ALLEGRO_COLOR col_lhook = al_map_rgba(170,170,170,info_opacity);
4048 ALLEGRO_COLOR col_stepable = al_map_rgba(165,105,8,info_opacity);
4049 ALLEGRO_COLOR col_dmg = al_map_rgba(255,255,0,info_opacity);
4050 newcombo const &c = combobuf[cmbdat];
4051
4052 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
4053
4054 int32_t xx = x-viewport.x;
4055 int32_t yy = y+playing_field_offset-viewport.y;
4056
4057 int32_t bridgedetected = 0;
4058
4059 // Draw damage combos
4060 bool dmg = combo_class_buf[c.type].modify_hp_amount;
4061
4062 for(int32_t i=0; i<4; i++)
4063 {
4064 int32_t tx=((i&2)<<2)+xx;
4065 int32_t ty=((i&1)<<3)+yy;
4066 int32_t tx2=((i&2)<<2)+x;
4067 int32_t ty2=((i&1)<<3)+y;
4068 for (int32_t m = lyr-1; m <= 1; m++)
4069 {
4070 if (get_qr(qr_OLD_BRIDGE_COMBOS))
4071 {
4072 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && !_walkflag_layer(tx2, ty2, m))
4073 {
4074 bridgedetected |= (1<<i);
4075 }
4076 }
4077 else
4078 {
4079 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && _effectflag_layer(tx2, ty2, m))
4080 {
4081 bridgedetected |= (1<<i);
4082 }
4083 }
4084 }
4085 if ((bridgedetected & (1<<i)))
4086 continue;
4087 bool doladdercheck = true;
4088
4089 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
4090 {
4091 for(int32_t k=0; k<8; k+=2)
4092 for(int32_t j=0; j<8; j+=2)
4093 if(((k+j)/2)%2)
4094 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_water1);
4095 }
4096 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
4097 {
4098 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
4099 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
4100 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_water1);
4101 else al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_lhook);
4102 }
4103
4104 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
4105 {
4106 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
4107 {
4108 for(int32_t k=0; k<8; k+=2)
4109 for(int32_t j=0; j<8; j+=2)
4110 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,((k+j)/2)%2 ? col_stepable : col_lhook);
4111 }
4112 else
4113 {
4114 ALLEGRO_COLOR* color = &col_solid;
4115
4116 if(isstepable(cmbdat)&& (!doladdercheck))
4117 color=&col_stepable;
4118 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4119 color=&col_lhook;
4120
4121 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,*color);
4122 }
4123 }
4124
4125 if(dmg)
4126 {
4127 for(int32_t k=0; k<8; k+=2)
4128 for(int32_t j=0; j<8; j+=2)
4129 if((k+j)%4 < 2) al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_dmg);
4130 }
4131 }
4132 }
4133
4134 void put_effectflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
4135 {
4136 newcombo const &c = combobuf[cmbdat];
4137
4138 int32_t xx = x-xofs-viewport.x;
4139 int32_t yy = y+playing_field_offset-yofs-viewport.y;
4140
4141 for(int32_t i=0; i<4; i++)
4142 {
4143 int32_t tx=((i&2)<<2)+xx;
4144 int32_t ty=((i&1)<<3)+yy;
4145
4146 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4147 {
4148 int32_t color = vc(10);
4149
4150 rectfill(dest,tx,ty,tx+7,ty+7,color);
4151 }
4152 }
4153 }
4154 static void put_effectflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4155 {
4156 ALLEGRO_COLOR col_eff = al_map_rgba(85,255,85,info_opacity);
4157 newcombo const &c = combobuf[cmbdat];
4158
4159 int32_t xx = x-viewport.x;
4160 int32_t yy = y+playing_field_offset-viewport.y;
4161
4162 for(int32_t i=0; i<4; i++)
4163 {
4164 int32_t tx=((i&2)<<2)+xx;
4165 int32_t ty=((i&1)<<3)+yy;
4166
4167 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4168 {
4169 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_eff);
4170 }
4171 }
4172 }
4173
4174 void draw_ladder_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
4175 {
4176 for(auto cx = 0; cx < 256; cx += 16)
4177 {
4178 for(auto cy = 0; cy < 176; cy += 16)
4179 {
4180 if(isSVLadder(cx,cy))
4181 {
4182 auto nx = cx+x, ny = cy+y;
4183 if(cy && !isSVLadder(cx,cy-16))
4184 line(dest,nx,ny,nx+15,ny,c);
4185 rectfill(dest,nx,ny,nx+3,ny+15,c);
4186 rectfill(dest,nx+12,ny,nx+15,ny+15,c);
4187 rectfill(dest,nx+4,ny+2,nx+11,ny+5,c);
4188 rectfill(dest,nx+4,ny+10,nx+11,ny+13,c);
4189 }
4190 else if(isSVPlatform(cx,cy))
4191 {
4192 line(dest,cx+x,cy+y,cx+x+15,cy+y,c);
4193 }
4194 }
4195 }
4196 }
4197 void draw_ladder_platform_a5(int32_t x, int32_t y, ALLEGRO_COLOR c)
4198 {
4199 for(auto cx = 0; cx < 256; cx += 16)
4200 {
4201 for(auto cy = 0; cy < 176; cy += 16)
4202 {
4203 if(isSVLadder(cx,cy))
4204 {
4205 auto nx = cx+x, ny = cy+y;
4206 if(cy && !isSVLadder(cx,cy-16))
4207 al_draw_line(nx,ny,nx+15,ny,c,1);
4208 al_draw_filled_rectangle(nx,ny,nx+4,ny+16,c);
4209 al_draw_filled_rectangle(nx+12,ny,nx+16,ny+16,c);
4210 al_draw_filled_rectangle(nx+4,ny+2,nx+12,ny+6,c);
4211 al_draw_filled_rectangle(nx+4,ny+10,nx+12,ny+14,c);
4212 }
4213 else if(isSVPlatform(cx,cy))
4214 {
4215 al_draw_line(cx+x,cy+y,cx+x+15,cy+y,c,1);
4216 }
4217 }
4218 }
4219 }
4220
4221 // Walkflags L4 cheat
4222 void do_walkflags(const screen_handles_t& screen_handles, int32_t x, int32_t y)
4223 {
4224 if (!show_walkflags)
4225 return;
4226
4227 start_info_bmp();
4228
4229 mapscr* scr = screen_handles[0].scr;
4230 for(int32_t i=0; i<176; i++)
4231 {
4232 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4233 }
4234
4235 for(int32_t k=0; k<2; k++)
4236 {
4237 scr = screen_handles[k + 1].scr;
4238
4239 if (scr)
4240 {
4241 for(int32_t i=0; i<176; i++)
4242 {
4243 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], k%2+1);
4244 }
4245 }
4246 }
4247
4248 end_info_bmp();
4249 }
4250
4251 void do_walkflags(int32_t x, int32_t y)
4252 {
4253 if (!show_walkflags)
4254 return;
4255
4256 x += -viewport.x;
4257 y += playing_field_offset - viewport.y;
4258
4259 start_info_bmp();
4260
4261 draw_ladder_platform_a5(x,y,al_map_rgba(165,105,8,info_opacity));
4262 draw_solid_objects_a5(x,y,al_map_rgba(178,36,36,info_opacity));
4263 draw_slopes_a5(x,y,al_map_rgba(255,85,255,info_opacity));
4264
4265 end_info_bmp();
4266 }
4267
4268 // Effectflags L4 cheat
4269 void do_effectflags(mapscr* scr, int32_t x, int32_t y)
4270 {
4271 if(show_effectflags)
4272 {
4273 start_info_bmp();
4274
4275 for(int32_t i=0; i<176; i++)
4276 {
4277 put_effectflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4278 }
4279
4280 end_info_bmp();
4281 }
4282 }
4283
4284 272141 void calc_darkroom_combos(mapscr* scr, int offx, int offy)
4285 {
4286 272141 int map = scr->map;
4287 272141 int screen = scr->screen;
4288
4289
2/2
✓ Branch 0 taken 1904987 times.
✓ Branch 1 taken 272141 times.
2177128 for(int32_t lyr = 0; lyr < 7; ++lyr)
4290 {
4291 1904987 mapscr* scr = get_scr_layer(map, screen, lyr);
4292
2/2
✓ Branch 0 taken 780869 times.
✓ Branch 1 taken 1124118 times.
1904987 if (!scr->is_valid()) continue;
4293
4294
2/2
✓ Branch 0 taken 137432944 times.
✓ Branch 1 taken 780869 times.
138213813 for(int32_t q = 0; q < 176; ++q)
4295 {
4296 137432944 newcombo const& cmb = combobuf[scr->data[q]];
4297
2/2
✓ Branch 0 taken 136828325 times.
✓ Branch 1 taken 604619 times.
137432944 if(cmb.type == cTORCH)
4298 {
4299 604619 do_torch_combo(cmb, COMBOX(q)+8+offx, COMBOY(q)+8+offy, darkscr_bmp);
4300 604619 }
4301 137432944 }
4302 780869 }
4303 272141 }
4304
4305 272141 void calc_darkroom_ffcs(mapscr* scr, int offx, int offy)
4306 {
4307 272141 word c = scr->numFFC();
4308
2/2
✓ Branch 0 taken 537406 times.
✓ Branch 1 taken 272141 times.
809547 for(int q = 0; q < c; ++q)
4309 {
4310 537406 newcombo const& cmb = combobuf[scr->ffcs[q].data];
4311
2/2
✓ Branch 0 taken 522598 times.
✓ Branch 1 taken 14808 times.
537406 if(cmb.type == cTORCH)
4312 {
4313 14808 int cx = scr->ffcs[q].x.getInt()+(scr->ffEffectWidth(q)/2)+offx;
4314 14808 int cy = (scr->ffcs[q].y.getInt())+(scr->ffEffectHeight(q)/2)+offy;
4315 14808 do_torch_combo(cmb, cx, cy, darkscr_bmp);
4316 14808 }
4317 537406 }
4318 272141 }
4319
4320 struct nearby_screen_t
4321 {
4322 int screen;
4323 int offx;
4324 int offy;
4325 screen_handles_t screen_handles;
4326 };
4327 typedef std::vector<nearby_screen_t> nearby_screens_t;
4328
4329 15490027 static nearby_screens_t get_nearby_screens_non_scrolling_region()
4330 {
4331 15490027 nearby_screens_t nearby_screens;
4332
4333 15490027 mapscr* base_scr = origin_scr;
4334
1/2
✓ Branch 0 taken 15490027 times.
✗ Branch 1 not taken.
15490027 auto& nearby_screen = nearby_screens.emplace_back();
4335 15490027 nearby_screen.screen = cur_screen;
4336
1/2
✓ Branch 0 taken 15490027 times.
✗ Branch 1 not taken.
15490027 nearby_screen.screen_handles = create_screen_handles(base_scr);
4337
4338 15490027 return nearby_screens;
4339
1/2
✓ Branch 0 taken 15490027 times.
✗ Branch 1 not taken.
15490027 }
4340
4341 48296 static nearby_screens_t get_nearby_screens_scrolling_region()
4342 {
4343 48296 nearby_screens_t nearby_screens;
4344
4345
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x0 = viewport.left() / 256;
4346
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x1 = (viewport.right() - 1) / 256;
4347
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y0 = viewport.top() / 176;
4348
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y1 = (viewport.bottom() - 1) / 176;
4349
4350
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x0 = std::clamp(screens_x0, 0, 15);
4351
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x1 = std::clamp(screens_x1, 0, 15);
4352
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y0 = std::clamp(screens_y0, 0, 8);
4353
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y1 = std::clamp(screens_y1, 0, 8);
4354
4355
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 79928 times.
128224 for (int x = screens_x0; x <= screens_x1; x++)
4356 {
4357
2/2
✓ Branch 0 taken 169672 times.
✓ Branch 1 taken 79928 times.
249600 for (int y = screens_y0; y <= screens_y1; y++)
4358 {
4359 169672 int screen = cur_screen + x + y*16;
4360
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!is_in_current_region(screen)) continue;
4361
4362
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 mapscr* base_scr = get_scr(screen);
4363
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!base_scr->is_valid()) continue;
4364
4365
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
4366
4367
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto& nearby_screen = nearby_screens.emplace_back();
4368 169672 nearby_screen.screen = screen;
4369 169672 nearby_screen.offx = offx;
4370 169672 nearby_screen.offy = offy;
4371
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 nearby_screen.screen_handles = create_screen_handles(base_scr);
4372 169672 }
4373 79928 }
4374
4375 48296 return nearby_screens;
4376
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 }
4377
4378 3658 static nearby_screens_t get_nearby_screens_smooth_maze()
4379 {
4380 3658 nearby_screens_t nearby_screens;
4381
4382
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x0 = viewport.left() / 256;
4383
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x1 = (viewport.right() - 1) / 256;
4384
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y0 = viewport.top() / 176;
4385
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y1 = (viewport.bottom() - 1) / 176;
4386
4387
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.left() < 0) screens_x0--;
4388
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.top() < 0) screens_y0--;
4389
4390
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 7308 times.
10966 for (int x = screens_x0; x <= screens_x1; x++)
4391 {
4392
2/2
✓ Branch 0 taken 18600 times.
✓ Branch 1 taken 7308 times.
25908 for (int y = screens_y0; y <= screens_y1; y++)
4393 {
4394 18600 int screen = -1;
4395 mapscr* base_scr;
4396 int offx, offy;
4397
4398 18600 mapscr* maze_scr = maze_state.scr;
4399 18600 int maze_screen = maze_scr->screen;
4400
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_x = get_region_relative_dx(maze_screen);
4401
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_y = get_region_relative_dy(maze_screen);
4402 18600 int maze_screen_dx = x - maze_screen_x;
4403 18600 int maze_screen_dy = y - maze_screen_y;
4404 18600 int exitdir = maze_scr->exitdir;
4405
4406 bool should_draw_maze_screen;
4407
2/2
✓ Branch 0 taken 9052 times.
✓ Branch 1 taken 9548 times.
18600 if (maze_state.lost)
4408 {
4409 9548 should_draw_maze_screen = true;
4410 9548 }
4411 else
4412 {
4413 9052 should_draw_maze_screen = true;
4414
4/6
✓ Branch 0 taken 9052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6844 times.
✓ Branch 3 taken 2208 times.
✓ Branch 4 taken 6844 times.
✗ Branch 5 not taken.
9052 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != exitdir && XY_DELTA_TO_DIR(0, maze_screen_dy) != exitdir;
4415
2/2
✓ Branch 0 taken 3850 times.
✓ Branch 1 taken 5202 times.
9052 if (maze_state.enter_dir != dir_invalid)
4416
4/6
✓ Branch 0 taken 3850 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3304 times.
✓ Branch 3 taken 546 times.
✓ Branch 4 taken 3304 times.
✗ Branch 5 not taken.
3850 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != maze_state.enter_dir && XY_DELTA_TO_DIR(0, maze_screen_dy) != maze_state.enter_dir;
4417 }
4418
4419
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (should_draw_maze_screen)
4420 {
4421 16048 screen = maze_state.scr->screen;
4422 16048 base_scr = maze_state.scr;
4423
1/2
✓ Branch 0 taken 16048 times.
✗ Branch 1 not taken.
16048 std::tie(offx, offy) = translate_screen_coordinates_to_world(cur_screen + x + y*16);
4424 16048 }
4425
4426
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (screen == -1)
4427 {
4428 2552 screen = cur_screen + x + y*16;
4429
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!is_in_current_region(screen)) continue;
4430
4431
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 base_scr = get_scr(screen);
4432
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!base_scr->is_valid()) continue;
4433
4434
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 std::tie(offx, offy) = translate_screen_coordinates_to_world(screen);
4435 2552 }
4436
4437
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 auto& nearby_screen = nearby_screens.emplace_back();
4438 18600 nearby_screen.screen = screen;
4439 18600 nearby_screen.offx = offx;
4440 18600 nearby_screen.offy = offy;
4441
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 nearby_screen.screen_handles = create_screen_handles(base_scr);
4442 18600 }
4443 7308 }
4444
4445 3658 return nearby_screens;
4446
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 }
4447
4448 15541981 static nearby_screens_t get_nearby_screens()
4449 {
4450
4/4
✓ Branch 0 taken 9214 times.
✓ Branch 1 taken 15532767 times.
✓ Branch 2 taken 3658 times.
✓ Branch 3 taken 5556 times.
15541981 if (maze_state.active && maze_state.loopy)
4451 3658 return get_nearby_screens_smooth_maze();
4452
4453
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 15490027 times.
15538323 if (is_in_scrolling_region())
4454 48296 return get_nearby_screens_scrolling_region();
4455
4456 15490027 return get_nearby_screens_non_scrolling_region();
4457 15541981 }
4458
4459 202062210 static void for_every_nearby_screen(const nearby_screens_t& nearby_screens, const std::function <void (screen_handles_t, int, int, int)>& fn)
4460 {
4461
2/2
✓ Branch 0 taken 203846812 times.
✓ Branch 1 taken 202062210 times.
405909022 for (auto& nearby_screen : nearby_screens)
4462 203846812 fn(nearby_screen.screen_handles, nearby_screen.screen, nearby_screen.offx, nearby_screen.offy);
4463 202062210 }
4464
4465 124335848 static void draw_msgstr(byte layer, BITMAP* dest = nullptr)
4466 {
4467
2/2
✓ Branch 0 taken 15541981 times.
✓ Branch 1 taken 108793867 times.
124335848 if(layer != msgstr_layer) return;
4468
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 if(!dest) dest = framebuf;
4469
4470
2/2
✓ Branch 0 taken 679732 times.
✓ Branch 1 taken 14862249 times.
15541981 if(!(msg_bg_display_buf->clip))
4471 {
4472 679732 blit_msgstr_bg(dest,0,0,0,playing_field_offset,256,176);
4473 679732 }
4474
4475
2/2
✓ Branch 0 taken 679732 times.
✓ Branch 1 taken 14862249 times.
15541981 if(!(msg_portrait_display_buf->clip))
4476 {
4477 679732 blit_msgstr_prt(dest,0,0,0,playing_field_offset,256,176);
4478 679732 }
4479
4480
2/2
✓ Branch 0 taken 693139 times.
✓ Branch 1 taken 14848842 times.
15541981 if(!(msg_txt_display_buf->clip))
4481 {
4482 693139 blit_msgstr_fg(dest,0,0,0,playing_field_offset,256,176);
4483 693139 }
4484 124335848 }
4485
4486 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y);
4487
4488 62167924 static void set_draw_screen_clip(BITMAP* bmp)
4489 {
4490 62167924 set_clip_rect(bmp, draw_screen_clip_rect_x1, draw_screen_clip_rect_y1, draw_screen_clip_rect_x2, draw_screen_clip_rect_y2);
4491 62167924 }
4492
4493 46124807 void draw_screen(bool showhero, bool runGeneric)
4494 {
4495 46124807 clear_info_bmp();
4496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46124807 times.
46124807 if((GameFlags & (GAMEFLAG_SCRIPTMENU_ACTIVE|GAMEFLAG_F6SCRIPT_ACTIVE))!=0)
4497 {
4498 FFCore.doScriptMenuDraws();
4499 return;
4500 }
4501
4502
2/2
✓ Branch 0 taken 31183740 times.
✓ Branch 1 taken 14941067 times.
46124807 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_PRE_DRAW);
4503
4504 46124807 clear_bitmap(framebuf);
4505 46124807 clear_clip_rect(framebuf);
4506
4507 46124807 int32_t cmby2=0;
4508
4509 // Draw some background layers
4510 46124807 clear_bitmap(scrollbuf);
4511
4512 46124807 auto nearby_screens = get_nearby_screens();
4513
4514 // Handle layer 2/3 possibly being background layers.
4515
1/2
✓ Branch 0 taken 46124807 times.
✗ Branch 1 not taken.
61803106 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4516 15678299 mapscr* base_scr = screen_handles[0].base_scr;
4517
2/2
✓ Branch 0 taken 15551017 times.
✓ Branch 1 taken 127282 times.
15678299 if (XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4518 127282 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4519 15678299 });
4520
4521
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 45997525 times.
46124807 if (XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4522 {
4523
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 do_layer_primitives(scrollbuf, 2);
4524
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 particles.draw(scrollbuf, true, 2);
4525 127282 }
4526
2/2
✓ Branch 0 taken 15541981 times.
✓ Branch 1 taken 30582826 times.
46124807 _do_current_ffc_layer(scrollbuf, -2);
4527
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 15414699 times.
15541981 if (XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4528
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 draw_msgstr(2, scrollbuf);
4529
4530
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4531 15678299 mapscr* base_scr = screen_handles[0].base_scr;
4532
2/2
✓ Branch 0 taken 15585639 times.
✓ Branch 1 taken 92660 times.
15678299 if (XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4533 92660 do_layer(scrollbuf, 0, screen_handles[3], offx, offy);
4534 15678299 });
4535
4536
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15449321 times.
15541981 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4537 {
4538
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 do_layer_primitives(scrollbuf, 3);
4539
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 particles.draw(scrollbuf, true, 3);
4540 92660 }
4541
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(scrollbuf, -3);
4542
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15449321 times.
15541981 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4543
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 draw_msgstr(3, scrollbuf);
4544
4545 // Draw the main combo screens ("layer 0").
4546
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4547 15678299 mapscr* base_scr = screen_handles[0].base_scr;
4548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15678299 times.
15678299 if (lenscheck(base_scr, 0))
4549 {
4550 15678299 putscr(base_scr, scrollbuf, offx, offy + playing_field_offset);
4551 15678299 }
4552 15678299 });
4553
4554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15541981 times.
15541981 if (lenscheck(hero_scr, 0))
4555 {
4556
2/2
✓ Branch 0 taken 471085 times.
✓ Branch 1 taken 15070896 times.
15541981 if(!get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4557
3/4
✓ Branch 0 taken 471085 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4136 times.
✓ Branch 3 taken 466949 times.
475221 if(mblock2.draw(scrollbuf,0))
4558
1/2
✓ Branch 0 taken 4136 times.
✗ Branch 1 not taken.
4136 do_primitives(scrollbuf, SPLAYER_MOVINGBLOCK);
4559 15541981 }
4560
4561 // Lens hints, then primitives, then particles.
4562
6/10
✓ Branch 0 taken 15531952 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15531952 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15531952 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5876 times.
✓ Branch 9 taken 4153 times.
15541981 if((lensclk || (get_debug() && zc_getkey(KEY_L))) && !get_qr(qr_OLDLENSORDER))
4563 {
4564
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 draw_lens_under(scrollbuf, false);
4565
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4566 5876 }
4567
4568
2/4
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15541981 times.
✗ Branch 3 not taken.
15541981 if(show_layers[0] && lenscheck(hero_scr,0))
4569
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_primitives(scrollbuf, 0);
4570
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 particles.draw(scrollbuf, true, 0);
4571
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(scrollbuf, 0);
4572
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 draw_msgstr(0, scrollbuf);
4573
4574
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 set_draw_screen_clip(scrollbuf);
4575
4576
2/2
✓ Branch 0 taken 15198722 times.
✓ Branch 1 taken 343259 times.
15541981 if(!(get_qr(qr_LAYER12UNDERCAVE)))
4577 {
4578
4/4
✓ Branch 0 taken 15196848 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 53632 times.
✓ Branch 3 taken 15108464 times.
30360818 if(showhero &&
4579
4/6
✓ Branch 0 taken 15196848 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15162096 times.
✓ Branch 3 taken 34752 times.
✓ Branch 4 taken 15162096 times.
✗ Branch 5 not taken.
15196848 ((Hero.getAction()==climbcovertop)||(Hero.getAction()==climbcoverbottom)))
4580 {
4581
3/4
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53632 times.
✓ Branch 3 taken 34752 times.
88384 if(Hero.getAction()==climbcovertop)
4582 {
4583 34752 cmby2=16;
4584 34752 }
4585
2/4
✓ Branch 0 taken 53632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53632 times.
53632 else if(Hero.getAction()==climbcoverbottom)
4586 {
4587 53632 cmby2=-16;
4588 53632 }
4589
4590
1/2
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
88384 decorations.draw2(scrollbuf,true);
4591
1/2
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
88384 Hero.draw(scrollbuf);
4592
1/2
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
88384 decorations.draw(scrollbuf,true);
4593
2/4
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
88384 int32_t ccx = (int32_t)Hero.getClimbCoverX();
4594
2/4
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
88384 int32_t ccy = (int32_t)Hero.getClimbCoverY();
4595
4596
3/6
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88384 times.
✗ Branch 5 not taken.
88384 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4597
3/6
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88384 times.
✗ Branch 5 not taken.
88384 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4598
4599
4/6
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15232 times.
✓ Branch 5 taken 73152 times.
88384 if(int32_t(Hero.getX())&15)
4600 {
4601
3/6
✓ Branch 0 taken 15232 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15232 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15232 times.
✗ Branch 5 not taken.
15232 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4602
3/6
✓ Branch 0 taken 15232 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15232 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15232 times.
✗ Branch 5 not taken.
15232 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4603 15232 }
4604 88384 }
4605 15198722 }
4606
4607
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4608 15678299 do_layer(scrollbuf, 0, screen_handles[1], offx, offy); // LAYER 1
4609 15678299 });
4610
4611
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_layer_primitives(scrollbuf, 1);
4612
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 particles.draw(scrollbuf, true, 1);
4613
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(scrollbuf, 1);
4614
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 draw_msgstr(1, scrollbuf);
4615
4616 // Handle layer 2 NOT being used as background layers.
4617
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4618 15678299 mapscr* base_scr = screen_handles[0].base_scr;
4619
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 15551017 times.
15678299 if (!XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4620 15551017 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4621 15678299 });
4622
4623
2/2
✓ Branch 0 taken 15414699 times.
✓ Branch 1 taken 127282 times.
15541981 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4624 {
4625
1/2
✓ Branch 0 taken 15414699 times.
✗ Branch 1 not taken.
15414699 do_layer_primitives(scrollbuf, 2);
4626
1/2
✓ Branch 0 taken 15414699 times.
✗ Branch 1 not taken.
15414699 particles.draw(scrollbuf, true, 2);
4627 15414699 }
4628
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(scrollbuf, 2);
4629
2/2
✓ Branch 0 taken 15414699 times.
✓ Branch 1 taken 127282 times.
15541981 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4630
1/2
✓ Branch 0 taken 15414699 times.
✗ Branch 1 not taken.
15414699 draw_msgstr(2, scrollbuf);
4631
4632
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_primitives(scrollbuf, SPLAYER_FFC_DRAW);
4633
4634
2/2
✓ Branch 0 taken 343259 times.
✓ Branch 1 taken 15198722 times.
15541981 if(get_qr(qr_LAYER12UNDERCAVE))
4635 {
4636
2/4
✓ Branch 0 taken 343259 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 343259 times.
686518 if(showhero &&
4637
3/6
✓ Branch 0 taken 343259 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 343259 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 343259 times.
✗ Branch 5 not taken.
343259 ((Hero.getAction()==climbcovertop)||(Hero.getAction()==climbcoverbottom)))
4638 {
4639 if(Hero.getAction()==climbcovertop)
4640 {
4641 cmby2=16;
4642 }
4643 else if(Hero.getAction()==climbcoverbottom)
4644 {
4645 cmby2=-16;
4646 }
4647
4648 decorations.draw2(scrollbuf,true);
4649 Hero.draw(scrollbuf);
4650 decorations.draw(scrollbuf,true);
4651 int32_t ccx = (int32_t)(Hero.getClimbCoverX());
4652 int32_t ccy = (int32_t)(Hero.getClimbCoverY());
4653
4654 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4655 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4656
4657 if(int32_t(Hero.getX())&15)
4658 {
4659 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4660 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4661 }
4662 }
4663 343259 }
4664
4665
2/2
✓ Branch 0 taken 471085 times.
✓ Branch 1 taken 15070896 times.
15541981 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4666 {
4667
1/2
✓ Branch 0 taken 15070896 times.
✗ Branch 1 not taken.
30278110 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4668 15207214 do_layer(scrollbuf, -2, screen_handles[0], offx, offy); // push blocks!
4669
2/2
✓ Branch 0 taken 14476500 times.
✓ Branch 1 taken 730714 times.
15207214 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4670 {
4671 730714 do_layer(scrollbuf, -2, screen_handles[1], offx, offy); // push blocks!
4672 730714 do_layer(scrollbuf, -2, screen_handles[2], offx, offy); // push blocks!
4673 730714 }
4674 15207214 });
4675
4676
1/2
✓ Branch 0 taken 15070896 times.
✗ Branch 1 not taken.
15070896 do_primitives(scrollbuf, SPLAYER_PUSHBLOCK);
4677 15070896 }
4678
4679 // Show walkflags cheat
4680
2/4
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15541981 times.
15541981 if (show_walkflags || show_effectflags)
4681 {
4682 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4683 do_walkflags(screen_handles, offx, offy);
4684 do_effectflags(screen_handles[0].base_scr, offx, offy);
4685 });
4686
4687 do_walkflags(0, 0);
4688 }
4689
4690
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 putscrdoors(nearby_screens, scrollbuf, 0, playing_field_offset);
4691
4692 // Lens hints, doors etc.
4693
4/8
✓ Branch 0 taken 15531952 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15531952 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15531952 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
15541981 if(lensclk || (get_debug() && zc_getkey(KEY_L)))
4694 {
4695
2/2
✓ Branch 0 taken 4153 times.
✓ Branch 1 taken 5876 times.
10029 if(get_qr(qr_OLDLENSORDER))
4696 {
4697
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 draw_lens_under(scrollbuf, false);
4698
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4699 4153 }
4700
4701
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 draw_lens_under(scrollbuf, true);
4702
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_2);
4703 10029 }
4704
4705 // Blit those layers onto framebuf
4706
4707
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 set_draw_screen_clip(framebuf);
4708
4709
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 blit(scrollbuf, framebuf, 0, 0, 0, 0, 256, 232);
4710
4711 // After this point, scrollbuf is no longer drawn to - so things like dosubscr have access to a "partially rendered" frame.
4712 // I think only used for COOLSCROLL==0? Seems like a silly feature...
4713
4714 // Draw the subscreen, without clipping
4715
2/2
✓ Branch 0 taken 9248963 times.
✓ Branch 1 taken 6293018 times.
15541981 if(!get_qr(qr_SUBSCREENOVERSPRITES))
4716 {
4717 9248963 bool dotime = false;
4718
4/6
✓ Branch 0 taken 9248963 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3412853 times.
✓ Branch 3 taken 5836110 times.
✓ Branch 4 taken 3412853 times.
✗ Branch 5 not taken.
9248963 if (replay_version_check(22)) dotime = game->should_show_time();
4719
1/2
✓ Branch 0 taken 9248963 times.
✗ Branch 1 not taken.
9248963 put_passive_subscr(framebuf, 0, 0, dotime, sspUP);
4720 9248963 }
4721
4722 // Draw some sprites onto framebuf
4723
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 set_clip_rect(framebuf,0,0,256,232);
4724
4725
2/2
✓ Branch 0 taken 99496 times.
✓ Branch 1 taken 15442485 times.
15541981 if(!(pricesdisplaybuf->clip))
4726 {
4727
1/2
✓ Branch 0 taken 99496 times.
✗ Branch 1 not taken.
99496 masked_blit(pricesdisplaybuf,framebuf,0,0,0,playing_field_offset,256,176);
4728 99496 }
4729
4730
5/6
✓ Branch 0 taken 15496355 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15490027 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15541981 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4731 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4732
4733
8/10
✓ Branch 0 taken 15540107 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 15540107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15505355 times.
✓ Branch 5 taken 34752 times.
✓ Branch 6 taken 15505355 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15451723 times.
✓ Branch 9 taken 53632 times.
15541981 if(showhero && ((Hero.getAction()!=climbcovertop)&&(Hero.getAction()!=climbcoverbottom)))
4734 {
4735
1/2
✓ Branch 0 taken 15451723 times.
✗ Branch 1 not taken.
15451723 Hero.draw_under(framebuf);
4736
4737
3/4
✓ Branch 0 taken 15451723 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 141385 times.
✓ Branch 3 taken 15310338 times.
15451723 if(Hero.isSwimming())
4738 {
4739
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 decorations.draw2(framebuf,true);
4740
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 Hero.draw(framebuf);
4741
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 decorations.draw(framebuf,true);
4742 141385 }
4743 15451723 }
4744
4745
2/2
✓ Branch 0 taken 26095 times.
✓ Branch 1 taken 15515886 times.
15541981 if(drawguys)
4746 {
4747
4/4
✓ Branch 0 taken 1980253 times.
✓ Branch 1 taken 13535633 times.
✓ Branch 2 taken 989876 times.
✓ Branch 3 taken 990377 times.
15515886 if(get_qr(qr_NOFLICKER) || (frame&1))
4748 {
4749 // Just clips sprites if in a repeating, smooth maze.
4750
2/2
✓ Branch 0 taken 14516295 times.
✓ Branch 1 taken 9214 times.
14525509 bool do_clip = maze_state.active && maze_state.loopy;
4751
4752
3/4
✓ Branch 0 taken 23626748 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9101239 times.
✓ Branch 3 taken 14525509 times.
23626748 for(int32_t i=0; i<Ewpns.Count(); i++)
4753 {
4754
3/4
✓ Branch 0 taken 9101239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✓ Branch 3 taken 8903296 times.
9101239 if(((weapon *)Ewpns.spr(i))->behind)
4755
2/4
✓ Branch 0 taken 197943 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✗ Branch 3 not taken.
197943 Ewpns.spr(i)->draw(framebuf);
4756 9101239 }
4757
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
4758
4759
3/4
✓ Branch 0 taken 19199493 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4673984 times.
✓ Branch 3 taken 14525509 times.
19199493 for(int32_t i=0; i<Lwpns.Count(); i++)
4760 {
4761
3/4
✓ Branch 0 taken 4673984 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✓ Branch 3 taken 4670779 times.
4673984 if(((weapon *)Lwpns.spr(i))->behind)
4762
2/4
✓ Branch 0 taken 3205 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✗ Branch 3 not taken.
3205 Lwpns.spr(i)->draw(framebuf);
4763 4673984 }
4764
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
4765
4766
6/6
✓ Branch 0 taken 9789858 times.
✓ Branch 1 taken 4735651 times.
✓ Branch 2 taken 1348300 times.
✓ Branch 3 taken 8441558 times.
✓ Branch 4 taken 674011 times.
✓ Branch 5 taken 674289 times.
14525509 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4767 {
4768
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 9111911 times.
9115569 if (do_clip)
4769
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.drawshadow_smooth_maze(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
4770 else
4771
1/2
✓ Branch 0 taken 9111911 times.
✗ Branch 1 not taken.
9111911 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
4772 9115569 }
4773
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14521851 times.
14525509 if (do_clip)
4774
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.draw_smooth_maze(framebuf);
4775 else
4776
1/2
✓ Branch 0 taken 14521851 times.
✗ Branch 1 not taken.
14521851 guys.draw(framebuf,true);
4777
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14521851 times.
14525509 if (do_clip)
4778 {
4779 3658 int maze_screen = maze_state.scr->screen;
4780
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4781
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4782 3658 }
4783
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 do_primitives(framebuf, SPLAYER_NPC_DRAW);
4784
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14521851 times.
14525509 if (do_clip)
4785
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
4786
4787
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 chainlinks.draw(framebuf,true);
4788
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4789 //Lwpns.draw(framebuf,true);
4790
4791
3/4
✓ Branch 0 taken 23626748 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9101239 times.
✓ Branch 3 taken 14525509 times.
23626748 for(int32_t i=0; i<Ewpns.Count(); i++)
4792 {
4793
3/4
✓ Branch 0 taken 9101239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8903296 times.
✓ Branch 3 taken 197943 times.
9101239 if(!((weapon *)Ewpns.spr(i))->behind)
4794
2/4
✓ Branch 0 taken 8903296 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8903296 times.
✗ Branch 3 not taken.
8903296 Ewpns.spr(i)->draw(framebuf);
4795 9101239 }
4796
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
4797
4798
3/4
✓ Branch 0 taken 19199493 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4673984 times.
✓ Branch 3 taken 14525509 times.
19199493 for(int32_t i=0; i<Lwpns.Count(); i++)
4799 {
4800
3/4
✓ Branch 0 taken 4673984 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4670779 times.
✓ Branch 3 taken 3205 times.
4673984 if(!((weapon *)Lwpns.spr(i))->behind)
4801
2/4
✓ Branch 0 taken 4670779 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4670779 times.
✗ Branch 3 not taken.
4670779 Lwpns.spr(i)->draw(framebuf);
4802 4673984 }
4803
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
4804
4805
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14521851 times.
14525509 if (do_clip)
4806
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 items.draw_smooth_maze(framebuf);
4807 else
4808
1/2
✓ Branch 0 taken 14521851 times.
✗ Branch 1 not taken.
14521851 items.draw(framebuf,true);
4809
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14521851 times.
14525509 if (do_clip)
4810 {
4811 3658 int maze_screen = maze_state.scr->screen;
4812
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4813
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4814 3658 }
4815
1/2
✓ Branch 0 taken 14525509 times.
✗ Branch 1 not taken.
14525509 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
4816
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14521851 times.
14525509 if (do_clip)
4817
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
4818 14525509 }
4819 else
4820 {
4821
3/4
✓ Branch 0 taken 1495195 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 504818 times.
✓ Branch 3 taken 990377 times.
1495195 for(int32_t i=0; i<Ewpns.Count(); i++)
4822 {
4823
3/4
✓ Branch 0 taken 504818 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✓ Branch 3 taken 496173 times.
504818 if(((weapon *)Ewpns.spr(i))->behind)
4824
2/4
✓ Branch 0 taken 8645 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✗ Branch 3 not taken.
8645 Ewpns.spr(i)->draw(framebuf);
4825 504818 }
4826
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
4827
4828
3/4
✓ Branch 0 taken 1220949 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230572 times.
✓ Branch 3 taken 990377 times.
1220949 for(int32_t i=0; i<Lwpns.Count(); i++)
4829 {
4830
2/4
✓ Branch 0 taken 230572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 230572 times.
230572 if(((weapon *)Lwpns.spr(i))->behind)
4831 Lwpns.spr(i)->draw(framebuf);
4832 230572 }
4833
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
4834
4835
3/4
✓ Branch 0 taken 228620 times.
✓ Branch 1 taken 761757 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 228620 times.
990377 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4836 {
4837
1/2
✓ Branch 0 taken 228620 times.
✗ Branch 1 not taken.
228620 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
4838 228620 }
4839
4840
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 items.draw(framebuf,false);
4841
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
4842
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 chainlinks.draw(framebuf,false);
4843
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4844 //Lwpns.draw(framebuf,false);
4845
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 guys.draw(framebuf,false);
4846
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 do_primitives(framebuf, SPLAYER_NPC_DRAW);
4847
4848
3/4
✓ Branch 0 taken 1495195 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 504818 times.
✓ Branch 3 taken 990377 times.
1495195 for(int32_t i=0; i<Ewpns.Count(); i++)
4849 {
4850
3/4
✓ Branch 0 taken 504818 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496173 times.
✓ Branch 3 taken 8645 times.
504818 if(!((weapon *)Ewpns.spr(i))->behind)
4851 {
4852
2/4
✓ Branch 0 taken 496173 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496173 times.
✗ Branch 3 not taken.
496173 Ewpns.spr(i)->draw(framebuf);
4853 496173 }
4854 504818 }
4855
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
4856
4857
3/4
✓ Branch 0 taken 1220949 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230572 times.
✓ Branch 3 taken 990377 times.
1220949 for(int32_t i=0; i<Lwpns.Count(); i++)
4858 {
4859
2/4
✓ Branch 0 taken 230572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230572 times.
✗ Branch 3 not taken.
230572 if(!((weapon *)Lwpns.spr(i))->behind)
4860 {
4861
2/4
✓ Branch 0 taken 230572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230572 times.
✗ Branch 3 not taken.
230572 Lwpns.spr(i)->draw(framebuf);
4862 230572 }
4863 230572 }
4864
1/2
✓ Branch 0 taken 990377 times.
✗ Branch 1 not taken.
990377 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
4865 }
4866
4867
1/2
✓ Branch 0 taken 15515886 times.
✗ Branch 1 not taken.
15515886 guys.draw2(framebuf,true);
4868 15515886 }
4869
4870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15541981 times.
15541981 if(mirror_portal.destdmap > -1)
4871 mirror_portal.draw(framebuf);
4872
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 portals.draw(framebuf,true);
4873
4874
8/10
✓ Branch 0 taken 15540107 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 15540107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15505355 times.
✓ Branch 5 taken 34752 times.
✓ Branch 6 taken 15505355 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15451723 times.
✓ Branch 9 taken 53632 times.
15541981 if(showhero && ((Hero.getAction()!=climbcovertop)&& (Hero.getAction()!=climbcoverbottom)))
4875 {
4876
2/2
✓ Branch 0 taken 14987054 times.
✓ Branch 1 taken 464669 times.
15451723 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4877 {
4878
1/2
✓ Branch 0 taken 14987054 times.
✗ Branch 1 not taken.
14987054 mblock2.draw(framebuf,-1);
4879
1/2
✓ Branch 0 taken 14987054 times.
✗ Branch 1 not taken.
14987054 do_primitives(framebuf, SPLAYER_MOVINGBLOCK);
4880 14987054 }
4881
3/4
✓ Branch 0 taken 15451723 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15310338 times.
✓ Branch 3 taken 141385 times.
15451723 if(!Hero.isSwimming())
4882 {
4883
8/12
✓ Branch 0 taken 15310338 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15310338 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15290728 times.
✓ Branch 5 taken 19610 times.
✓ Branch 6 taken 15290728 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15290728 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1370 times.
✓ Branch 11 taken 15308968 times.
15310338 if((Hero.getZ()>0 || Hero.getFakeZ()>0) &&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4884 {
4885
2/2
✓ Branch 0 taken 18925 times.
✓ Branch 1 taken 15291413 times.
15310338 Hero.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
4886 18925 }
4887
4888
6/8
✓ Branch 0 taken 15310338 times.
✓ Branch 1 taken 15291413 times.
✓ Branch 2 taken 15310338 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15310338 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15296027 times.
✓ Branch 7 taken 14311 times.
18925 if(Hero.getZ() <= (zfix)zinit.jump_hero_layer_threshold)
4889 {
4890
1/2
✓ Branch 0 taken 15296027 times.
✗ Branch 1 not taken.
15296027 decorations.draw2(framebuf,true);
4891
1/2
✓ Branch 0 taken 15296027 times.
✗ Branch 1 not taken.
15296027 Hero.draw(framebuf);
4892
1/2
✓ Branch 0 taken 15296027 times.
✗ Branch 1 not taken.
15296027 decorations.draw(framebuf,true);
4893 15296027 }
4894 15310338 }
4895 15451723 }
4896
4897
3/4
✓ Branch 0 taken 54879859 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39337878 times.
✓ Branch 3 taken 15541981 times.
54879859 for(int32_t i=0; i<guys.Count(); i++)
4898 {
4899
3/4
✓ Branch 0 taken 39337878 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15945120 times.
✓ Branch 3 taken 23392758 times.
39337878 if(((enemy*)guys.spr(i))->family == eeWALK)
4900 {
4901
3/4
✓ Branch 0 taken 15945120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7295 times.
✓ Branch 3 taken 15937825 times.
15945120 if(((eStalfos*)guys.spr(i))->hashero)
4902 {
4903
2/4
✓ Branch 0 taken 7295 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7295 times.
✗ Branch 3 not taken.
7295 guys.spr(i)->draw(framebuf);
4904 7295 }
4905 15945120 }
4906
4907
3/4
✓ Branch 0 taken 39337878 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 507162 times.
✓ Branch 3 taken 38830716 times.
39337878 if(((enemy*)guys.spr(i))->family == eeWALLM)
4908 {
4909
3/4
✓ Branch 0 taken 507162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✓ Branch 3 taken 505833 times.
507162 if(((eWallM*)guys.spr(i))->hashero)
4910 {
4911
2/4
✓ Branch 0 taken 1329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✗ Branch 3 not taken.
1329 guys.spr(i)->draw(framebuf);
4912 1329 }
4913 507162 }
4914
4915
11/20
✓ Branch 0 taken 39337878 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39337878 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39337878 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 39337878 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 39337878 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 39337878 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 39337878 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 39337878 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 39337878 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1342694 times.
✓ Branch 19 taken 37995184 times.
39337878 if(guys.spr(i)->z+guys.spr(i)->fakez > Hero.getZ()+Hero.getFakeZ())
4916 {
4917 //Jumping enemies in front of Hero.
4918
2/4
✓ Branch 0 taken 1342694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1342694 times.
✗ Branch 3 not taken.
1342694 guys.spr(i)->draw(framebuf);
4919 1342694 }
4920
1/2
✓ Branch 0 taken 39337878 times.
✗ Branch 1 not taken.
39337878 do_primitives(framebuf, SPLAYER_NPC_ABOVEPLAYER_DRAW);
4921 39337878 }
4922
4923 // Draw some layers onto framebuf
4924
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 set_draw_screen_clip(framebuf);
4925
5/6
✓ Branch 0 taken 15496355 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15490027 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15541981 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4926 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4927
4928 // Handle layer 3 NOT being used as background layers.
4929
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4930 15678299 mapscr* base_scr = screen_handles[0].base_scr;
4931
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15585639 times.
15678299 if (!XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4932 15585639 do_layer(framebuf, 0, screen_handles[3], offx, offy);
4933 15678299 });
4934
4935
2/2
✓ Branch 0 taken 15449321 times.
✓ Branch 1 taken 92660 times.
15541981 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4936 {
4937
1/2
✓ Branch 0 taken 15449321 times.
✗ Branch 1 not taken.
15449321 do_layer_primitives(framebuf, 3);
4938
1/2
✓ Branch 0 taken 15449321 times.
✗ Branch 1 not taken.
15449321 particles.draw(framebuf, true, 3);
4939 15449321 }
4940
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(framebuf, 3);
4941
2/2
✓ Branch 0 taken 15449321 times.
✓ Branch 1 taken 92660 times.
15541981 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4942
1/2
✓ Branch 0 taken 15449321 times.
✗ Branch 1 not taken.
15449321 draw_msgstr(3);
4943
4944
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4945 15678299 do_layer(framebuf, 0, screen_handles[4], offx, offy);
4946 15678299 });
4947
4948
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_layer_primitives(framebuf, 4);
4949
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 particles.draw(framebuf, true, 4);
4950
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(framebuf, 4);
4951
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 draw_msgstr(4);
4952
4953
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4954 15678299 do_layer(framebuf, -1, screen_handles[0], offx, offy);
4955
2/2
✓ Branch 0 taken 14397780 times.
✓ Branch 1 taken 1280519 times.
15678299 if (get_qr(qr_OVERHEAD_COMBOS_L1_L2))
4956 {
4957 1280519 do_layer(framebuf, -1, screen_handles[1], offx, offy);
4958 1280519 do_layer(framebuf, -1, screen_handles[2], offx, offy);
4959 1280519 }
4960 15678299 });
4961
4962
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_primitives(framebuf, SPLAYER_OVERHEAD_CMB);
4963
4964 // Draw some flying sprites onto framebuf
4965
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 clear_clip_rect(framebuf);
4966
5/6
✓ Branch 0 taken 15496355 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15490027 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15541981 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4967 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4968
4969 //Jumping Hero and jumping enemies are drawn on this layer.
4970
5/8
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15541981 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15541981 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14311 times.
✓ Branch 7 taken 15527670 times.
15541981 if(Hero.getZ() > (zfix)zinit.jump_hero_layer_threshold)
4971 {
4972
1/2
✓ Branch 0 taken 14311 times.
✗ Branch 1 not taken.
14311 decorations.draw2(framebuf,false);
4973
1/2
✓ Branch 0 taken 14311 times.
✗ Branch 1 not taken.
14311 Hero.draw(framebuf);
4974
1/2
✓ Branch 0 taken 14311 times.
✗ Branch 1 not taken.
14311 chainlinks.draw(framebuf,true);
4975
1/2
✓ Branch 0 taken 14311 times.
✗ Branch 1 not taken.
14311 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4976
4977
3/4
✓ Branch 0 taken 17053 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✓ Branch 3 taken 14311 times.
17053 for(int32_t i=0; i<Lwpns.Count(); i++)
4978 {
4979
9/16
✓ Branch 0 taken 2742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2742 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2742 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2742 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2742 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2742 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 239 times.
✓ Branch 15 taken 2503 times.
2742 if(Lwpns.spr(i)->z+Lwpns.spr(i)->fakez > (zfix)zinit.jump_hero_layer_threshold)
4980 {
4981
2/4
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 239 times.
✗ Branch 3 not taken.
239 Lwpns.spr(i)->draw(framebuf);
4982 239 }
4983 2742 }
4984
1/2
✓ Branch 0 taken 14311 times.
✗ Branch 1 not taken.
14311 do_primitives(framebuf, SPLAYER_LWEAP_ABOVE_DRAW);
4985
4986
1/2
✓ Branch 0 taken 14311 times.
✗ Branch 1 not taken.
14311 decorations.draw(framebuf,false);
4987 14311 }
4988
4989
5/6
✓ Branch 0 taken 3288982 times.
✓ Branch 1 taken 12252999 times.
✓ Branch 2 taken 44334015 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32081016 times.
✓ Branch 5 taken 12252999 times.
47622997 if(!get_qr(qr_ENEMIESZAXIS)) for(int32_t i=0; i<guys.Count(); i++)
4990 {
4991
13/22
✓ Branch 0 taken 32081016 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32081016 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27175260 times.
✓ Branch 5 taken 4905756 times.
✓ Branch 6 taken 27175260 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27175260 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27175260 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27175260 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 27175260 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 27175260 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 27175260 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 6568 times.
✓ Branch 21 taken 27168692 times.
32081016 if((isflier(guys.spr(i)->id)) || (guys.spr(i)->z+guys.spr(i)->fakez) > (zfix)zinit.jump_hero_layer_threshold)
4992 {
4993
2/4
✓ Branch 0 taken 4912324 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4912324 times.
✗ Branch 3 not taken.
4912324 guys.spr(i)->draw(framebuf);
4994 4912324 }
4995 44334015 }
4996 else
4997 {
4998
3/4
✓ Branch 0 taken 10545844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7256862 times.
✓ Branch 3 taken 3288982 times.
10545844 for(int32_t i=0; i<guys.Count(); i++)
4999 {
5000
13/22
✓ Branch 0 taken 7256862 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7256862 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6081157 times.
✓ Branch 5 taken 1175705 times.
✓ Branch 6 taken 6081157 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6081157 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6081157 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5594346 times.
✓ Branch 13 taken 486811 times.
✓ Branch 14 taken 5594346 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5594346 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5594346 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5594346 times.
7256862 if((isflier(guys.spr(i)->id)) || guys.spr(i)->z > 0 || guys.spr(i)->fakez > 0)
5001 {
5002
2/4
✓ Branch 0 taken 1662516 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1662516 times.
✗ Branch 3 not taken.
1662516 guys.spr(i)->draw(framebuf);
5003 1662516 }
5004 7256862 }
5005 }
5006
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_primitives(framebuf, SPLAYER_NPC_AIRBORNE_DRAW);
5007
5008 // Draw the Moving Fairy above layer 3
5009
3/4
✓ Branch 0 taken 18686870 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3144889 times.
✓ Branch 3 taken 15541981 times.
18686870 for(int32_t i=0; i<items.Count(); i++)
5010
6/8
✓ Branch 0 taken 3144889 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69867 times.
✓ Branch 3 taken 3075022 times.
✓ Branch 4 taken 69867 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 60153 times.
✓ Branch 7 taken 9714 times.
3205042 if(itemsbuf[items.spr(i)->id].family == itype_fairy && itemsbuf[items.spr(i)->id].misc3)
5011
2/4
✓ Branch 0 taken 60153 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60153 times.
✗ Branch 3 not taken.
60153 items.spr(i)->draw(framebuf);
5012
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_primitives(framebuf, SPLAYER_FAIRYITEM_DRAW);
5013
5014 // Draw some layers onto framebuf
5015
5016
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 set_draw_screen_clip(framebuf);
5017
5018
2/2
✓ Branch 0 taken 15527629 times.
✓ Branch 1 taken 14352 times.
15541981 if (lightbeam_present)
5019 {
5020 14352 color_map = &trans_table2;
5021
2/2
✓ Branch 0 taken 13114 times.
✓ Branch 1 taken 1238 times.
14352 if(get_qr(qr_LIGHTBEAM_TRANSPARENT))
5022
1/2
✓ Branch 0 taken 13114 times.
✗ Branch 1 not taken.
13114 draw_trans_sprite(framebuf, lightbeam_bmp, 0, playing_field_offset);
5023 else
5024
1/2
✓ Branch 0 taken 1238 times.
✗ Branch 1 not taken.
1238 masked_blit(lightbeam_bmp, framebuf, 0, 0, 0, playing_field_offset, 256, 176);
5025 14352 color_map = &trans_table;
5026 14352 }
5027
5028
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5029 15678299 do_layer(framebuf, 0, screen_handles[5], offx, offy);
5030 15678299 });
5031
5032
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_layer_primitives(framebuf, 5);
5033
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 particles.draw(framebuf, true, 5);
5034
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(framebuf, 5);
5035
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 draw_msgstr(5);
5036
5037
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(framebuf, -1); // 'overhead' freeform combos
5038
5039
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_primitives(framebuf, SPLAYER_OVERHEAD_FFC);
5040
5041
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5042 15678299 do_layer(framebuf, 0, screen_handles[6], offx, offy);
5043 15678299 });
5044
5045
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 do_layer_primitives(framebuf, 6);
5046
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 particles.draw(framebuf, true, 6);
5047
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(framebuf, 6);
5048
5049 15541981 bool any_dark = false;
5050
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5051 15678299 mapscr* base_scr = screen_handles[0].scr;
5052 15678299 any_dark |= is_dark(base_scr);
5053 15678299 });
5054
5055 // Handle low drawn darkness
5056
4/4
✓ Branch 0 taken 1274183 times.
✓ Branch 1 taken 14267798 times.
✓ Branch 2 taken 1030412 times.
✓ Branch 3 taken 243771 times.
15541981 if(get_qr(qr_NEW_DARKROOM) && any_dark)
5057 {
5058
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5059 250005 mapscr* base_scr = screen_handles[0].scr;
5060 250005 calc_darkroom_combos(base_scr, offx, offy + playing_field_offset);
5061 250005 calc_darkroom_ffcs(base_scr, 0, playing_field_offset);
5062 250005 });
5063
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 if(showhero)
5064
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 Hero.calc_darkroom_hero(0, -playing_field_offset);
5065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 243771 times.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5066 250005 mapscr* base_scr = screen_handles[0].scr;
5067
2/2
✓ Branch 0 taken 245275 times.
✓ Branch 1 taken 4730 times.
250005 if (!is_dark(base_scr))
5068 {
5069 4730 offy += playing_field_offset;
5070 4730 rectfill(darkscr_bmp, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5071 4730 rectfill(darkscr_bmp_trans, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5072 4730 }
5073 250005 });
5074 243771 }
5075
5076 //Darkroom if under the subscreen
5077
6/6
✓ Branch 0 taken 1274183 times.
✓ Branch 1 taken 14267798 times.
✓ Branch 2 taken 823284 times.
✓ Branch 3 taken 450899 times.
✓ Branch 4 taken 231780 times.
✓ Branch 5 taken 591504 times.
15541981 if(get_qr(qr_NEW_DARKROOM) && get_qr(qr_NEWDARK_L6) && any_dark)
5078 {
5079
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5080
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231780 times.
231780 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5082 {
5083 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5084 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5085 }
5086
5087 231780 color_map = &trans_table2;
5088
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 231636 times.
231780 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5089 {
5090
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5091
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5092
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5093 144 }
5094 else
5095 {
5096
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5097
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5098 }
5099 231780 color_map = &trans_table;
5100
5101
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5102
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5103 231780 }
5104
5105
3/6
✓ Branch 0 taken 45626 times.
✓ Branch 1 taken 15496355 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45626 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
15541981 if (is_extended_height_mode() && lensclk && !FFCore.system_suspend[susptLENS])
5106 {
5107 draw_lens_over();
5108 --lensclk;
5109 }
5110
5111 // Draw some text on framebuf
5112
5113
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 set_clip_rect(framebuf,0,0,256,232);
5114
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 if(!get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5115
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 draw_msgstr(6);
5116
5117 // Draw the subscreen, without clipping
5118
2/2
✓ Branch 0 taken 6293018 times.
✓ Branch 1 taken 9248963 times.
15541981 if(get_qr(qr_SUBSCREENOVERSPRITES))
5119 {
5120
2/4
✓ Branch 0 taken 6293018 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6293018 times.
✗ Branch 3 not taken.
6293018 put_passive_subscr(framebuf, 0, 0, game->should_show_time(), sspUP);
5121
5122 // Draw primitives over subscren
5123
1/2
✓ Branch 0 taken 6293018 times.
✗ Branch 1 not taken.
6293018 do_primitives(framebuf, 7); //Layer '7' appears above subscreen if quest rule is set
5124 6293018 }
5125
5126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15541981 times.
15541981 if(get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5127 draw_msgstr(6);
5128
5129 // Handle high-drawn darkness
5130
6/6
✓ Branch 0 taken 1274183 times.
✓ Branch 1 taken 14267798 times.
✓ Branch 2 taken 450899 times.
✓ Branch 3 taken 823284 times.
✓ Branch 4 taken 11991 times.
✓ Branch 5 taken 438908 times.
15541981 if(get_qr(qr_NEW_DARKROOM) && !get_qr(qr_NEWDARK_L6) && any_dark)
5131 {
5132
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5133
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5135 {
5136 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5137 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5138 }
5139
5140 11991 color_map = &trans_table2;
5141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5142 {
5143 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5144 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5145 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5146 }
5147 else
5148 {
5149
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5150
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5151 }
5152 11991 color_map = &trans_table;
5153
5154
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5155
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5156 11991 }
5157
5158
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 _do_current_ffc_layer(framebuf, 7);
5159
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 draw_msgstr(7);
5160
5161
1/2
✓ Branch 0 taken 15541981 times.
✗ Branch 1 not taken.
15541981 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
5162
3/4
✓ Branch 0 taken 14941067 times.
✓ Branch 1 taken 600914 times.
✓ Branch 2 taken 14941067 times.
✗ Branch 3 not taken.
15541981 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_POST_DRAW);
5163 76707633 }
5164
5165 // TODO: separate setting door data and drawing door
5166 28146 void put_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t type, bool redraw, bool even_walls)
5167 {
5168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28146 times.
28146 if (type > 8) return;
5169
5170 28146 int32_t d=scr->door_combo_set;
5171
5172
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15604 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12542 times.
28146 switch(type)
5173 {
5174 case dt_wall:
5175 case dt_walk:
5176 if(!even_walls)
5177 break;
5178 [[fallthrough]];
5179 case dt_pass:
5180
3/4
✓ Branch 0 taken 1036 times.
✓ Branch 1 taken 11506 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1036 times.
12542 if(!get_qr(qr_REPLACEOPENDOORS) && !even_walls)
5181 1036 break;
5182 [[fallthrough]];
5183 case dt_lock:
5184 case dt_shut:
5185 case dt_boss:
5186 case dt_olck:
5187 case dt_osht:
5188 case dt_obos:
5189 case dt_bomb:
5190
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 7255 times.
✓ Branch 2 taken 6781 times.
✓ Branch 3 taken 6362 times.
✓ Branch 4 taken 6712 times.
27110 switch(side)
5191 {
5192 case up:
5193 7255 scr->data[pos] = DoorComboSets[d].doorcombo_u[type][0];
5194 7255 scr->cset[pos] = DoorComboSets[d].doorcset_u[type][0];
5195 7255 scr->sflag[pos] = 0;
5196 7255 scr->data[pos+1] = DoorComboSets[d].doorcombo_u[type][1];
5197 7255 scr->cset[pos+1] = DoorComboSets[d].doorcset_u[type][1];
5198 7255 scr->sflag[pos+1] = 0;
5199 7255 scr->data[pos+16] = DoorComboSets[d].doorcombo_u[type][2];
5200 7255 scr->cset[pos+16] = DoorComboSets[d].doorcset_u[type][2];
5201 7255 scr->sflag[pos+16] = 0;
5202 7255 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_u[type][3];
5203 7255 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_u[type][3];
5204 7255 scr->sflag[pos+16+1] = 0;
5205
5206
2/2
✓ Branch 0 taken 5433 times.
✓ Branch 1 taken 1822 times.
7255 if(redraw)
5207 {
5208 3644 putcombo(dest,(pos&15)<<4,pos&0xF0,
5209 1822 DoorComboSets[d].doorcombo_u[type][0],
5210 1822 DoorComboSets[d].doorcset_u[type][0]);
5211 3644 putcombo(dest,((pos&15)<<4)+16,pos&0xF0,
5212 1822 DoorComboSets[d].doorcombo_u[type][1],
5213 1822 DoorComboSets[d].doorcset_u[type][1]);
5214 1822 }
5215
5216 7255 break;
5217
5218 case down:
5219 6781 scr->data[pos] = DoorComboSets[d].doorcombo_d[type][0];
5220 6781 scr->cset[pos] = DoorComboSets[d].doorcset_d[type][0];
5221 6781 scr->sflag[pos] = 0;
5222 6781 scr->data[pos+1] = DoorComboSets[d].doorcombo_d[type][1];
5223 6781 scr->cset[pos+1] = DoorComboSets[d].doorcset_d[type][1];
5224 6781 scr->sflag[pos+1] = 0;
5225 6781 scr->data[pos+16] = DoorComboSets[d].doorcombo_d[type][2];
5226 6781 scr->cset[pos+16] = DoorComboSets[d].doorcset_d[type][2];
5227 6781 scr->sflag[pos+16] = 0;
5228 6781 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_d[type][3];
5229 6781 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_d[type][3];
5230 6781 scr->sflag[pos+16+1] = 0;
5231
5232
2/2
✓ Branch 0 taken 5462 times.
✓ Branch 1 taken 1319 times.
6781 if(redraw)
5233 {
5234 2638 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5235 1319 DoorComboSets[d].doorcombo_d[type][2],
5236 1319 DoorComboSets[d].doorcset_d[type][2]);
5237 2638 putcombo(dest,((pos&15)<<4)+16,(pos&0xF0)+16,
5238 1319 DoorComboSets[d].doorcombo_d[type][3],
5239 1319 DoorComboSets[d].doorcset_d[type][3]);
5240 1319 }
5241
5242 6781 break;
5243
5244 case left:
5245 6362 scr->data[pos] = DoorComboSets[d].doorcombo_l[type][0];
5246 6362 scr->cset[pos] = DoorComboSets[d].doorcset_l[type][0];
5247 6362 scr->sflag[pos] = 0;
5248 6362 scr->data[pos+1] = DoorComboSets[d].doorcombo_l[type][1];
5249 6362 scr->cset[pos+1] = DoorComboSets[d].doorcset_l[type][1];
5250 6362 scr->sflag[pos+1] = 0;
5251 6362 scr->data[pos+16] = DoorComboSets[d].doorcombo_l[type][2];
5252 6362 scr->cset[pos+16] = DoorComboSets[d].doorcset_l[type][2];
5253 6362 scr->sflag[pos+16] = 0;
5254 6362 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_l[type][3];
5255 6362 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_l[type][3];
5256 6362 scr->sflag[pos+16+1] = 0;
5257 6362 scr->data[pos+32] = DoorComboSets[d].doorcombo_l[type][4];
5258 6362 scr->cset[pos+32] = DoorComboSets[d].doorcset_l[type][4];
5259 6362 scr->sflag[pos+32] = 0;
5260 6362 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_l[type][5];
5261 6362 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_l[type][5];
5262 6362 scr->sflag[pos+32+1] = 0;
5263
5264
2/2
✓ Branch 0 taken 4873 times.
✓ Branch 1 taken 1489 times.
6362 if(redraw)
5265 {
5266 2978 putcombo(dest,(pos&15)<<4,pos&0xF0,
5267 1489 DoorComboSets[d].doorcombo_l[type][0],
5268 1489 DoorComboSets[d].doorcset_l[type][0]);
5269 2978 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5270 1489 DoorComboSets[d].doorcombo_l[type][2],
5271 1489 DoorComboSets[d].doorcset_l[type][2]);
5272 2978 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5273 1489 DoorComboSets[d].doorcombo_l[type][4],
5274 1489 DoorComboSets[d].doorcset_l[type][4]);
5275 1489 }
5276
5277 6362 break;
5278
5279 case right:
5280 6712 scr->data[pos] = DoorComboSets[d].doorcombo_r[type][0];
5281 6712 scr->cset[pos] = DoorComboSets[d].doorcset_r[type][0];
5282 6712 scr->sflag[pos] = 0;
5283 6712 scr->data[pos+1] = DoorComboSets[d].doorcombo_r[type][1];
5284 6712 scr->cset[pos+1] = DoorComboSets[d].doorcset_r[type][1];
5285 6712 scr->sflag[pos+1] = 0;
5286 6712 scr->data[pos+16] = DoorComboSets[d].doorcombo_r[type][2];
5287 6712 scr->cset[pos+16] = DoorComboSets[d].doorcset_r[type][2];
5288 6712 scr->sflag[pos+16] = 0;
5289 6712 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_r[type][3];
5290 6712 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_r[type][3];
5291 6712 scr->sflag[pos+16+1] = 0;
5292 6712 scr->data[pos+32] = DoorComboSets[d].doorcombo_r[type][4];
5293 6712 scr->cset[pos+32] = DoorComboSets[d].doorcset_r[type][4];
5294 6712 scr->sflag[pos+32] = 0;
5295 6712 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_r[type][5];
5296 6712 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_r[type][5];
5297 6712 scr->sflag[pos+32+1] = 0;
5298
5299
2/2
✓ Branch 0 taken 5058 times.
✓ Branch 1 taken 1654 times.
6712 if(redraw)
5300 {
5301 3308 putcombo(dest,(pos&15)<<4,pos&0xF0,
5302 1654 DoorComboSets[d].doorcombo_r[type][0],
5303 1654 DoorComboSets[d].doorcset_r[type][0]);
5304 3308 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5305 1654 DoorComboSets[d].doorcombo_r[type][2],
5306 1654 DoorComboSets[d].doorcset_r[type][2]);
5307 3308 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5308 1654 DoorComboSets[d].doorcombo_r[type][4],
5309 1654 DoorComboSets[d].doorcset_r[type][4]);
5310 1654 }
5311
5312 6712 break;
5313 }
5314
5315 27110 break;
5316
5317 default:
5318 break;
5319 }
5320 28146 }
5321
5322 706556 static void over_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t offx, int32_t offy)
5323 {
5324 706556 int32_t door_combo_set = scr->door_combo_set;
5325 706556 int32_t x = (pos&15)<<4;
5326 706556 int32_t y = (pos&0xF0);
5327 706556 int32_t d = door_combo_set;
5328 706556 x += offx;
5329 706556 y += offy;
5330
5331
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 161136 times.
✓ Branch 2 taken 179643 times.
✓ Branch 3 taken 196353 times.
✓ Branch 4 taken 169424 times.
706556 switch(side)
5332 {
5333 case up:
5334 322272 overcombo2(dest,x,y,
5335 161136 DoorComboSets[d].bombdoorcombo_u[0],
5336 161136 DoorComboSets[d].bombdoorcset_u[0]);
5337 322272 overcombo2(dest,x+16,y,
5338 161136 DoorComboSets[d].bombdoorcombo_u[1],
5339 161136 DoorComboSets[d].bombdoorcset_u[1]);
5340 161136 break;
5341
5342 case down:
5343 359286 overcombo2(dest,x,y,
5344 179643 DoorComboSets[d].bombdoorcombo_d[0],
5345 179643 DoorComboSets[d].bombdoorcset_d[0]);
5346 359286 overcombo2(dest,x+16,y,
5347 179643 DoorComboSets[d].bombdoorcombo_d[1],
5348 179643 DoorComboSets[d].bombdoorcset_d[1]);
5349 179643 break;
5350
5351 case left:
5352 392706 overcombo2(dest,x,y,
5353 196353 DoorComboSets[d].bombdoorcombo_l[0],
5354 196353 DoorComboSets[d].bombdoorcset_l[0]);
5355 392706 overcombo2(dest,x,y+16,
5356 196353 DoorComboSets[d].bombdoorcombo_l[1],
5357 196353 DoorComboSets[d].bombdoorcset_l[1]);
5358 392706 overcombo2(dest,x,y+16,
5359 196353 DoorComboSets[d].bombdoorcombo_l[2],
5360 196353 DoorComboSets[d].bombdoorcset_l[2]);
5361 196353 break;
5362
5363 case right:
5364 338848 overcombo2(dest,x,y,
5365 169424 DoorComboSets[d].bombdoorcombo_r[0],
5366 169424 DoorComboSets[d].bombdoorcset_r[0]);
5367 338848 overcombo2(dest,x,y+16,
5368 169424 DoorComboSets[d].bombdoorcombo_r[1],
5369 169424 DoorComboSets[d].bombdoorcset_r[1]);
5370 338848 overcombo2(dest,x,y+16,
5371 169424 DoorComboSets[d].bombdoorcombo_r[2],
5372 169424 DoorComboSets[d].bombdoorcset_r[2]);
5373 169424 break;
5374 }
5375 706556 }
5376
5377 47560 void update_door(mapscr* scr, int32_t side, int32_t door, bool even_walls)
5378 {
5379
7/8
✓ Branch 0 taken 47452 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 47452 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22922 times.
✓ Branch 5 taken 24530 times.
✓ Branch 6 taken 530 times.
✓ Branch 7 taken 22392 times.
47560 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5380 25168 return;
5381
5382 int32_t doortype;
5383
5384
10/12
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 655 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 12492 times.
✓ Branch 5 taken 910 times.
✓ Branch 6 taken 1553 times.
✓ Branch 7 taken 3190 times.
✓ Branch 8 taken 1693 times.
✓ Branch 9 taken 172 times.
✓ Branch 10 taken 67 times.
✓ Branch 11 taken 1138 times.
22392 switch(door)
5385 {
5386 case dWALL:
5387 doortype=dt_wall;
5388 break;
5389
5390 case dWALK:
5391 doortype=dt_walk;
5392 break;
5393
5394 case dOPEN:
5395 12492 doortype=dt_pass;
5396 12492 break;
5397
5398 case dLOCKED:
5399 910 doortype=dt_lock;
5400 910 break;
5401
5402 case dUNLOCKED:
5403 1553 doortype=dt_olck;
5404 1553 break;
5405
5406 case dSHUTTER:
5407
3/4
✓ Branch 0 taken 2782 times.
✓ Branch 1 taken 408 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2782 times.
3190 if(screenscrolling && ((HeroDir()^1)==side))
5408 {
5409 doortype=dt_osht;
5410 get_screen_state(scr->screen).open_doors = -4;
5411 break;
5412 }
5413
5414 [[fallthrough]];
5415 case d1WAYSHUTTER:
5416 3712 doortype=dt_shut;
5417 3712 break;
5418
5419 case dOPENSHUTTER:
5420 1693 doortype=dt_osht;
5421 1693 break;
5422
5423 case dBOSS:
5424 172 doortype=dt_boss;
5425 172 break;
5426
5427 case dOPENBOSS:
5428 67 doortype=dt_obos;
5429 67 break;
5430
5431 case dBOMBED:
5432 1138 doortype=dt_bomb;
5433 1138 break;
5434
5435 default:
5436 655 return;
5437 }
5438
5439
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5627 times.
✓ Branch 2 taken 5769 times.
✓ Branch 3 taken 5111 times.
✓ Branch 4 taken 5230 times.
21737 switch(side)
5440 {
5441 case up:
5442 5627 put_door(scr,nullptr,7,side,doortype,false,even_walls);
5443 5627 break;
5444
5445 case down:
5446 5769 put_door(scr,nullptr,151,side,doortype,false,even_walls);
5447 5769 break;
5448
5449 case left:
5450 5111 put_door(scr,nullptr,64,side,doortype,false,even_walls);
5451 5111 break;
5452
5453 case right:
5454 5230 put_door(scr,nullptr,78,side,doortype,false,even_walls);
5455 5230 break;
5456 }
5457 47560 }
5458
5459 6500 void putdoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t door, bool redraw, bool even_walls)
5460 {
5461 /*
5462 #define dWALL 0 // 000 0
5463 #define dBOMB 6 // 011 0
5464 #define 8 // 100 0
5465 enum {dt_pass=0, dt_lock, dt_shut, dt_boss, dt_olck, dt_osht, dt_obos, dt_wall, dt_bomb, dt_walk, dt_max};
5466 */
5467
5468
7/8
✓ Branch 0 taken 6500 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6496 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 6413 times.
✓ Branch 5 taken 83 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 6405 times.
6500 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5469 91 return;
5470
5471 int32_t doortype;
5472
5473
8/12
✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 362 times.
✓ Branch 7 taken 1529 times.
✓ Branch 8 taken 3955 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 51 times.
✓ Branch 11 taken 231 times.
6409 switch(door)
5474 {
5475 case dWALL:
5476 doortype=dt_wall;
5477 break;
5478
5479 case dWALK:
5480 doortype=dt_walk;
5481 break;
5482
5483 case dOPEN:
5484 50 doortype=dt_pass;
5485 50 break;
5486
5487 case dLOCKED:
5488 doortype=dt_lock;
5489 break;
5490
5491 case dUNLOCKED:
5492 362 doortype=dt_olck;
5493 362 break;
5494
5495 case dSHUTTER:
5496
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1529 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1529 if(screenscrolling && ((HeroDir()^1)==side))
5497 {
5498 doortype=dt_osht;
5499 get_screen_state(cur_screen).open_doors = -4;
5500 break;
5501 }
5502
5503 [[fallthrough]];
5504 case d1WAYSHUTTER:
5505 1756 doortype=dt_shut;
5506 1756 break;
5507
5508 case dOPENSHUTTER:
5509 3955 doortype=dt_osht;
5510 3955 break;
5511
5512 case dBOSS:
5513 4 doortype=dt_boss;
5514 4 break;
5515
5516 case dOPENBOSS:
5517 51 doortype=dt_obos;
5518 51 break;
5519
5520 case dBOMBED:
5521 231 doortype=dt_bomb;
5522 231 break;
5523
5524 default:
5525 return;
5526 }
5527
5528
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 1858 times.
✓ Branch 2 taken 1355 times.
✓ Branch 3 taken 1514 times.
✓ Branch 4 taken 1682 times.
6409 switch(side)
5529 {
5530 case up:
5531
2/2
✓ Branch 0 taken 1789 times.
✓ Branch 1 taken 69 times.
1858 switch(door)
5532 {
5533 case dBOMBED:
5534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
138 if(redraw)
5535 {
5536 69 over_door(scr,dest,39,side,0,0);
5537 69 }
5538 [[fallthrough]];
5539 default:
5540 1858 put_door(scr,dest,7,side,doortype,redraw, even_walls);
5541 1858 break;
5542 }
5543
5544 1858 break;
5545
5546 case down:
5547
2/2
✓ Branch 0 taken 1316 times.
✓ Branch 1 taken 39 times.
1355 switch(door)
5548 {
5549 case dBOMBED:
5550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
78 if(redraw)
5551 {
5552 39 over_door(scr,dest,135,side,0,0);
5553 39 }
5554 [[fallthrough]];
5555 default:
5556 1355 put_door(scr,dest,151,side,doortype,redraw, even_walls);
5557 1355 break;
5558 }
5559
5560 1355 break;
5561
5562 case left:
5563
2/2
✓ Branch 0 taken 1463 times.
✓ Branch 1 taken 51 times.
1514 switch(door)
5564 {
5565 case dBOMBED:
5566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
102 if(redraw)
5567 {
5568 51 over_door(scr,dest,66,side,0,0);
5569 51 }
5570 [[fallthrough]];
5571 default:
5572 1514 put_door(scr,dest,64,side,doortype,redraw, even_walls);
5573 1514 break;
5574 }
5575
5576 1514 break;
5577
5578 case right:
5579
2/2
✓ Branch 0 taken 1610 times.
✓ Branch 1 taken 72 times.
1682 switch(door)
5580 {
5581 case dBOMBED:
5582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
144 if(redraw)
5583 {
5584 72 over_door(scr,dest,77,side,0,0);
5585 72 }
5586 [[fallthrough]];
5587 default:
5588 1682 put_door(scr,dest,78,side,doortype,redraw, even_walls);
5589 1682 break;
5590 }
5591
5592 1682 break;
5593 }
5594 6500 }
5595
5596 586 void putcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5597 {
5598
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if(combo!=0)
5599 {
5600 586 putcombo(dest,x, y, combo, cset);
5601 586 }
5602 586 }
5603
5604 293 void overcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5605 {
5606
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 74 times.
293 if(combo!=0)
5607 {
5608 219 overcombo(dest,x, y, combo, cset);
5609 219 }
5610 293 }
5611
5612 125 void showbombeddoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t offx, int32_t offy)
5613 {
5614 125 int32_t d = scr->door_combo_set;
5615
5616
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 37 times.
125 switch(side)
5617 {
5618 case up:
5619 86 putcombo_not_zero(dest,((7&15)<<4) + offx,(7&0xF0) + offy,
5620 43 DoorComboSets[d].doorcombo_u[dt_bomb][0],
5621 43 DoorComboSets[d].doorcset_u[dt_bomb][0]);
5622 86 putcombo_not_zero(dest,((8&15)<<4) + offx,(8&0xF0) + offy,
5623 43 DoorComboSets[d].doorcombo_u[dt_bomb][1],
5624 43 DoorComboSets[d].doorcset_u[dt_bomb][1]);
5625 86 putcombo_not_zero(dest,((23&15)<<4) + offx,(23&0xF0) + offy,
5626 43 DoorComboSets[d].doorcombo_u[dt_bomb][2],
5627 43 DoorComboSets[d].doorcset_u[dt_bomb][2]);
5628 86 putcombo_not_zero(dest,((24&15)<<4) + offx,(24&0xF0) + offy,
5629 43 DoorComboSets[d].doorcombo_u[dt_bomb][3],
5630 43 DoorComboSets[d].doorcset_u[dt_bomb][3]);
5631 86 overcombo_not_zero(dest,((39&15)<<4) + offx,(39&0xF0) + offy,
5632 43 DoorComboSets[d].bombdoorcombo_u[0],
5633 43 DoorComboSets[d].bombdoorcset_u[0]);
5634 86 overcombo_not_zero(dest,((40&15)<<4) + offx,(40&0xF0) + offy,
5635 43 DoorComboSets[d].bombdoorcombo_u[1],
5636 43 DoorComboSets[d].bombdoorcset_u[1]);
5637 43 break;
5638
5639 case down:
5640 78 putcombo_not_zero(dest,((151&15)<<4) + offx,(151&0xF0) + offy,
5641 39 DoorComboSets[d].doorcombo_d[dt_bomb][0],
5642 39 DoorComboSets[d].doorcset_d[dt_bomb][0]);
5643 78 putcombo_not_zero(dest,((152&15)<<4) + offx,(152&0xF0) + offy,
5644 39 DoorComboSets[d].doorcombo_d[dt_bomb][1],
5645 39 DoorComboSets[d].doorcset_d[dt_bomb][1]);
5646 78 putcombo_not_zero(dest,((167&15)<<4) + offx,(167&0xF0) + offy,
5647 39 DoorComboSets[d].doorcombo_d[dt_bomb][2],
5648 39 DoorComboSets[d].doorcset_d[dt_bomb][2]);
5649 78 putcombo_not_zero(dest,((168&15)<<4) + offx,(168&0xF0) + offy,
5650 39 DoorComboSets[d].doorcombo_d[dt_bomb][3],
5651 39 DoorComboSets[d].doorcset_d[dt_bomb][3]);
5652 78 overcombo_not_zero(dest,((135&15)<<4) + offx,(135&0xF0) + offy,
5653 39 DoorComboSets[d].bombdoorcombo_d[0],
5654 39 DoorComboSets[d].bombdoorcset_d[0]);
5655 78 overcombo_not_zero(dest,((136&15)<<4) + offx,(136&0xF0) + offy,
5656 39 DoorComboSets[d].bombdoorcombo_d[1],
5657 39 DoorComboSets[d].bombdoorcset_d[1]);
5658 39 break;
5659
5660 case left:
5661 12 putcombo_not_zero(dest,((64&15)<<4) + offx,(64&0xF0) + offy,
5662 6 DoorComboSets[d].doorcombo_l[dt_bomb][0],
5663 6 DoorComboSets[d].doorcset_l[dt_bomb][0]);
5664 12 putcombo_not_zero(dest,((65&15)<<4) + offx,(65&0xF0) + offy,
5665 6 DoorComboSets[d].doorcombo_l[dt_bomb][1],
5666 6 DoorComboSets[d].doorcset_l[dt_bomb][1]);
5667 12 putcombo_not_zero(dest,((80&15)<<4) + offx,(80&0xF0) + offy,
5668 6 DoorComboSets[d].doorcombo_l[dt_bomb][2],
5669 6 DoorComboSets[d].doorcset_l[dt_bomb][2]);
5670 12 putcombo_not_zero(dest,((81&15)<<4) + offx,(81&0xF0) + offy,
5671 6 DoorComboSets[d].doorcombo_l[dt_bomb][3],
5672 6 DoorComboSets[d].doorcset_l[dt_bomb][3]);
5673 12 putcombo_not_zero(dest,((96&15)<<4) + offx,(96&0xF0) + offy,
5674 6 DoorComboSets[d].doorcombo_l[dt_bomb][4],
5675 6 DoorComboSets[d].doorcset_l[dt_bomb][4]);
5676 12 putcombo_not_zero(dest,((97&15)<<4) + offx,(97&0xF0) + offy,
5677 6 DoorComboSets[d].doorcombo_l[dt_bomb][5],
5678 6 DoorComboSets[d].doorcset_l[dt_bomb][5]);
5679 12 overcombo_not_zero(dest,((66&15)<<4) + offx,(66&0xF0) + offy,
5680 6 DoorComboSets[d].bombdoorcombo_l[0],
5681 6 DoorComboSets[d].bombdoorcset_l[0]);
5682 12 overcombo_not_zero(dest,((82&15)<<4) + offx,(82&0xF0) + offy,
5683 6 DoorComboSets[d].bombdoorcombo_l[1],
5684 6 DoorComboSets[d].bombdoorcset_l[1]);
5685 12 overcombo_not_zero(dest,((98&15)<<4) + offx,(98&0xF0) + offy,
5686 6 DoorComboSets[d].bombdoorcombo_l[2],
5687 6 DoorComboSets[d].bombdoorcset_l[2]);
5688 6 break;
5689
5690 case right:
5691 74 putcombo_not_zero(dest,((78&15)<<4) + offx,(78&0xF0) + offy,
5692 37 DoorComboSets[d].doorcombo_r[dt_bomb][0],
5693 37 DoorComboSets[d].doorcset_r[dt_bomb][0]);
5694 74 putcombo_not_zero(dest,((79&15)<<4) + offx,(79&0xF0) + offy,
5695 37 DoorComboSets[d].doorcombo_r[dt_bomb][1],
5696 37 DoorComboSets[d].doorcset_r[dt_bomb][1]);
5697 74 putcombo_not_zero(dest,((94&15)<<4) + offx,(94&0xF0) + offy,
5698 37 DoorComboSets[d].doorcombo_r[dt_bomb][2],
5699 37 DoorComboSets[d].doorcset_r[dt_bomb][2]);
5700 74 putcombo_not_zero(dest,((95&15)<<4) + offx,(95&0xF0) + offy,
5701 37 DoorComboSets[d].doorcombo_r[dt_bomb][3],
5702 37 DoorComboSets[d].doorcset_r[dt_bomb][3]);
5703 74 putcombo_not_zero(dest,((110&15)<<4) + offx,(110&0xF0) + offy,
5704 37 DoorComboSets[d].doorcombo_r[dt_bomb][4],
5705 37 DoorComboSets[d].doorcset_r[dt_bomb][4]);
5706 74 putcombo_not_zero(dest,((111&15)<<4) + offx,(111&0xF0) + offy,
5707 37 DoorComboSets[d].doorcombo_r[dt_bomb][5],
5708 37 DoorComboSets[d].doorcset_r[dt_bomb][5]);
5709 74 overcombo_not_zero(dest,((77&15)<<4) + offx,(77&0xF0) + offy,
5710 37 DoorComboSets[d].bombdoorcombo_r[0],
5711 37 DoorComboSets[d].bombdoorcset_r[0]);
5712 74 overcombo_not_zero(dest,((93&15)<<4) + offx,(93&0xF0) + offy,
5713 37 DoorComboSets[d].bombdoorcombo_r[1],
5714 37 DoorComboSets[d].bombdoorcset_r[1]);
5715 74 overcombo_not_zero(dest,((109&15)<<4) + offx,(109&0xF0) + offy,
5716 37 DoorComboSets[d].bombdoorcombo_r[2],
5717 37 DoorComboSets[d].bombdoorcset_r[2]);
5718 37 break;
5719 }
5720 125 }
5721
5722 5362163 void openshutters(mapscr* scr)
5723 {
5724 5362163 bool opened_door = false;
5725
2/2
✓ Branch 0 taken 5362163 times.
✓ Branch 1 taken 21448652 times.
26810815 for(int32_t i=0; i<4; i++)
5726
2/2
✓ Branch 0 taken 21444697 times.
✓ Branch 1 taken 3955 times.
21452607 if(scr->door[i]==dSHUTTER)
5727 {
5728 3955 putdoor(scr, scrollbuf, i, dOPENSHUTTER);
5729 3955 scr->door[i]=dOPENSHUTTER;
5730 3955 opened_door = true;
5731 3955 }
5732
5733 5362163 auto& combo_cache = combo_caches::shutter;
5734 2023696111 for_every_combo_in_screen(create_screen_handles(scr), [&](const auto& handle) {
5735
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2016723277 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1610668 times.
2018333948 if (!combo_cache.minis[handle.data()].shutter)
5736 2018333945 return;
5737 3 auto cid = handle.data();
5738 3 auto& cmb = handle.combo();
5739
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
5740 {
5741 3 auto& trig = cmb.triggers[idx];
5742
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(trig.triggerflags[0] & combotriggerSHUTTER)
5743 {
5744 3 do_trigger_combo(handle, idx);
5745
1/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(handle.data() != cid) break;
5746 }
5747 }
5748 2018333948 });
5749
5750
2/2
✓ Branch 0 taken 5359434 times.
✓ Branch 1 taken 2729 times.
5362163 if(opened_door)
5751 2729 sfx(WAV_DOOR,128);
5752 5362163 }
5753
5754 15119739 void clear_darkroom_bitmaps()
5755 {
5756 15119739 clear_to_color(darkscr_bmp, game->get_darkscr_color());
5757 15119739 clear_to_color(darkscr_bmp_trans, game->get_darkscr_color());
5758 15119739 }
5759
5760 16033341 bool is_dark(const mapscr* scr)
5761 {
5762 16033341 bool dark = scr->flags&fDARK;
5763
2/2
✓ Branch 0 taken 3722 times.
✓ Branch 1 taken 16029619 times.
16033341 if (region_is_lit) return !dark;
5764 16029619 return dark;
5765 16033341 }
5766
5767 39234 bool scrolling_is_dark(const mapscr* scr)
5768 {
5769 39234 bool dark = scr->flags&fDARK;
5770
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 39232 times.
39234 if (scrolling_region_is_lit) return !dark;
5771 39232 return dark;
5772 39234 }
5773
5774 36765 bool is_any_dark()
5775 {
5776 36765 bool dark = false;
5777 74786 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
5778 38021 dark |= (bool)(is_dark(scr));
5779 38021 });
5780 36765 return dark;
5781 }
5782
5783 411 static mapscr prev_origin_scrs[7];
5784 411 static std::set<int> loadscr_ffc_script_ids_to_remove;
5785
5786 static void handle_screen_overlay(const std::vector<mapscr*>& screens)
5787 {
5788 mapscr* base_scr = screens[0];
5789 mapscr* previous_scr = &prev_origin_scrs[0];
5790
5791 for (int i = 0; i < 176; i++)
5792 {
5793 if (base_scr->data[i] == 0)
5794 {
5795 base_scr->data[i] = previous_scr->data[i];
5796 base_scr->sflag[i] = previous_scr->sflag[i];
5797 base_scr->cset[i] = previous_scr->cset[i];
5798 }
5799 }
5800
5801 for (int i = 0; i < 6; i++)
5802 {
5803 if (previous_scr->layermap[i] > 0 && base_scr->layermap[i] > 0)
5804 {
5805 int lm = (base_scr->layermap[i]-1)*MAPSCRS+base_scr->layerscreen[i];
5806 int fm = (previous_scr->layermap[i]-1)*MAPSCRS+previous_scr->layerscreen[i];
5807
5808 for (int j = 0; j < 176; j++)
5809 {
5810 if (TheMaps[lm].data[j] == 0)
5811 {
5812 TheMaps[lm].data[j] = TheMaps[fm].data[j];
5813 TheMaps[lm].sflag[j] = TheMaps[fm].sflag[j];
5814 TheMaps[lm].cset[j] = TheMaps[fm].cset[j];
5815 }
5816 }
5817 }
5818 }
5819
5820 for (int i = 1; i <= 6; i++)
5821 {
5822 mapscr* scr = screens[i];
5823 previous_scr = &prev_origin_scrs[i];
5824
5825 if (scr->layermap[i] > 0)
5826 {
5827 for (int y = 0; y < 11; y++)
5828 {
5829 for (int x = 0; x < 16; x++)
5830 {
5831 int c = y*16+x;
5832
5833 if (scr->data[c]==0)
5834 {
5835 scr->data[c] = previous_scr->data[c];
5836 scr->sflag[c] = previous_scr->sflag[c];
5837 scr->cset[c] = previous_scr->cset[c];
5838 }
5839 }
5840 }
5841 }
5842 }
5843 }
5844
5845 37105 static void load_a_screen_and_layers_init(int dmap, int screen, int ldir, bool screen_overlay, bool ffc_overlay)
5846 {
5847 37105 std::vector<mapscr*> screens;
5848
5849
1/2
✓ Branch 0 taken 37105 times.
✗ Branch 1 not taken.
37105 const mapscr* source = get_canonical_scr(cur_map, screen);
5850
2/4
✓ Branch 0 taken 37105 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37105 times.
✗ Branch 3 not taken.
37105 mapscr* base_scr = new mapscr(*source);
5851 37105 temporary_screens[screen*7] = base_scr;
5852
1/2
✓ Branch 0 taken 37105 times.
✗ Branch 1 not taken.
37105 screens.push_back(base_scr);
5853
5854 37105 base_scr->valid |= mVALID; // layer 0 is always valid
5855
5856
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35861 times.
37105 if (screen == cur_screen)
5857 35861 origin_scr = base_scr;
5858
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35861 times.
37105 if (screen == hero_screen)
5859 35861 hero_scr = prev_hero_scr = base_scr;
5860
5861
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 36986 times.
37105 if (source->script > 0)
5862
1/2
✓ Branch 0 taken 119 times.
✗ Branch 1 not taken.
119 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
5863
5864
2/2
✓ Branch 0 taken 37105 times.
✓ Branch 1 taken 222630 times.
259735 for (int i = 0; i < 6; i++)
5865 {
5866
2/2
✓ Branch 0 taken 173523 times.
✓ Branch 1 taken 49107 times.
222630 if(source->layermap[i]>0)
5867 {
5868
3/6
✓ Branch 0 taken 49107 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 49107 times.
✗ Branch 5 not taken.
49107 mapscr* layer_scr = new mapscr(*get_canonical_scr(source->layermap[i]-1, source->layerscreen[i]));
5869 49107 layer_scr->map = cur_map;
5870 49107 layer_scr->screen = screen;
5871
1/2
✓ Branch 0 taken 49107 times.
✗ Branch 1 not taken.
49107 screens.push_back(layer_scr);
5872 49107 }
5873 else
5874 {
5875
1/2
✓ Branch 0 taken 173523 times.
✗ Branch 1 not taken.
173523 mapscr* layer_scr = new mapscr();
5876 173523 layer_scr->map = cur_map;
5877 173523 layer_scr->screen = screen;
5878
1/2
✓ Branch 0 taken 173523 times.
✗ Branch 1 not taken.
173523 screens.push_back(layer_scr);
5879 }
5880 222630 temporary_screens[screen*7+i+1] = screens[i+1];
5881 222630 }
5882
5883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37105 times.
37105 if (screen_overlay)
5884 handle_screen_overlay(screens);
5885
5886
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 36961 times.
37105 if (ffc_overlay)
5887 {
5888 144 mapscr* previous_scr = &prev_origin_scrs[0];
5889
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 int num_ffcs = previous_scr->numFFC();
5890
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 144 times.
4752 for (int i = 0; i < num_ffcs; i++)
5891 {
5892
2/2
✓ Branch 0 taken 4334 times.
✓ Branch 1 taken 274 times.
4608 if ((previous_scr->ffcs[i].flags&ffc_carryover))
5893 {
5894
2/4
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 274 times.
✗ Branch 3 not taken.
274 auto& ffc = base_scr->getFFC(i) = previous_scr->ffcs[i];
5895 274 ffc.screen_spawned = screen;
5896
5897
1/2
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
274 ffc_id_t ffc_id = get_region_screen_offset(screen)*MAXFFCS + i;
5898
1/2
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
274 loadscr_ffc_script_ids_to_remove.erase(ffc_id);
5899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 274 times.
274 if (previous_scr->ffcs[i].flags&ffc_scriptreset)
5900 {
5901 FFCore.reset_script_engine_data(ScriptType::FFC, ffc_id);
5902 }
5903 274 }
5904 4608 }
5905 144 }
5906
5907
1/2
✓ Branch 0 taken 37105 times.
✗ Branch 1 not taken.
1142082 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
5908
1/2
✓ Branch 0 taken 37105 times.
✗ Branch 1 not taken.
37105 int num_ffcs = base_scr->numFFC();
5909
2/2
✓ Branch 0 taken 1104977 times.
✓ Branch 1 taken 37105 times.
1142082 for (word i = 0; i < num_ffcs; i++)
5910 {
5911 1104977 base_scr->ffcs[i].screen_spawned = screen;
5912
1/2
✓ Branch 0 taken 1104977 times.
✗ Branch 1 not taken.
1104977 base_scr->ffcs[i].x += offx;
5913
1/2
✓ Branch 0 taken 1104977 times.
✗ Branch 1 not taken.
1104977 base_scr->ffcs[i].y += offy;
5914 1104977 }
5915 37105 }
5916
5917 37105 static void load_a_screen_and_layers_post(int dmap, int screen, int ldir)
5918 {
5919 37105 mapscr* base_scr = get_scr(screen);
5920 37105 int mi = mapind(cur_map, screen);
5921
5922 // Apply perm secrets, if applicable.
5923
2/2
✓ Branch 0 taken 11518 times.
✓ Branch 1 taken 25587 times.
37105 if (canPermSecret(dmap, screen))
5924 {
5925
2/2
✓ Branch 0 taken 23063 times.
✓ Branch 1 taken 2524 times.
25587 if(game->maps[mi] & mSECRET) // if special stuff done before
5926 {
5927 2524 reveal_hidden_stairs(base_scr, screen, false);
5928 2524 trigger_secrets_for_screen(TriggerSource::SecretsScreenState, base_scr, false);
5929 2524 }
5930
2/2
✓ Branch 0 taken 25584 times.
✓ Branch 1 taken 3 times.
25587 if(game->maps[mi] & mLIGHTBEAM) // if special stuff done before
5931 {
5932
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 3 times.
24 for (int layer = 0; layer <= 6; layer++)
5933 {
5934 21 mapscr* layer_scr = get_scr_layer(screen, layer);
5935
2/2
✓ Branch 0 taken 3696 times.
✓ Branch 1 taken 21 times.
3717 for (int pos = 0; pos < 176; pos++)
5936 {
5937 3696 newcombo const* cmb = &combobuf[layer_scr->data[pos]];
5938
2/2
✓ Branch 0 taken 3693 times.
✓ Branch 1 taken 3 times.
3696 if(cmb->type == cLIGHTTARGET)
5939 {
5940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!(cmb->usrflags&cflag1)) //Unlit version
5941 {
5942 3 layer_scr->data[pos] += 1;
5943 3 }
5944 3 }
5945 3696 }
5946 21 }
5947 3 }
5948 25587 }
5949
5950 37105 auto screen_handles = create_screen_handles(base_scr);
5951
5952 37105 int destlvl = DMaps[dmap].level;
5953 37105 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
5954 37105 toggle_gswitches_load(screen_handles);
5955
5956 37105 bool should_check_for_state_things = (screen < 0x80);
5957
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 36198 times.
37105 if (should_check_for_state_things)
5958 {
5959
2/2
✓ Branch 0 taken 35826 times.
✓ Branch 1 taken 372 times.
36198 if (game->maps[mi]&mLOCKBLOCK)
5960 372 remove_lockblocks(screen_handles);
5961
2/2
✓ Branch 0 taken 36140 times.
✓ Branch 1 taken 58 times.
36198 if (game->maps[mi]&mBOSSLOCKBLOCK)
5962 58 remove_bosslockblocks(screen_handles);
5963
2/2
✓ Branch 0 taken 36042 times.
✓ Branch 1 taken 156 times.
36198 if (game->maps[mi]&mCHEST)
5964 156 remove_chests(screen_handles);
5965
1/2
✓ Branch 0 taken 36198 times.
✗ Branch 1 not taken.
36198 if (game->maps[mi]&mLOCKEDCHEST)
5966 remove_lockedchests(screen_handles);
5967
2/2
✓ Branch 0 taken 36187 times.
✓ Branch 1 taken 11 times.
36198 if (game->maps[mi]&mBOSSCHEST)
5968 11 remove_bosschests(screen_handles);
5969
5970 36198 clear_xdoors_mi(screen_handles, mi, true);
5971 36198 clear_xstatecombos_mi(screen_handles, mi, true);
5972 36198 }
5973
5974 // check doors
5975
2/2
✓ Branch 0 taken 25586 times.
✓ Branch 1 taken 11519 times.
37105 if (isdungeon(dmap, screen))
5976 {
5977
2/2
✓ Branch 0 taken 46076 times.
✓ Branch 1 taken 11519 times.
57595 for(int32_t i=0; i<4; i++)
5978 {
5979 46076 int32_t door=base_scr->door[i];
5980
5981
5/5
✓ Branch 0 taken 5300 times.
✓ Branch 1 taken 36470 times.
✓ Branch 2 taken 2372 times.
✓ Branch 3 taken 230 times.
✓ Branch 4 taken 1704 times.
46076 switch(door)
5982 {
5983 case d1WAYSHUTTER:
5984 case dSHUTTER:
5985
3/4
✓ Branch 0 taken 1693 times.
✓ Branch 1 taken 3607 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1693 times.
5300 if ((ldir^1)==i && screen == hero_screen)
5986 {
5987 1693 base_scr->door[i]=dOPENSHUTTER;
5988 1693 }
5989
5990 5300 get_screen_state(screen).open_doors = -4;
5991 5300 break;
5992
5993 case dLOCKED:
5994
3/4
✓ Branch 0 taken 2372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1473 times.
✓ Branch 3 taken 899 times.
2372 if(should_check_for_state_things && game->maps[mi]&(1<<i))
5995 {
5996 1473 base_scr->door[i]=dUNLOCKED;
5997 1473 }
5998
5999 2372 break;
6000
6001 case dBOSS:
6002
3/4
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 168 times.
230 if(should_check_for_state_things && game->maps[mi]&(1<<i))
6003 {
6004 62 base_scr->door[i]=dOPENBOSS;
6005 62 }
6006
6007 230 break;
6008
6009 case dBOMB:
6010
3/4
✓ Branch 0 taken 1704 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1087 times.
✓ Branch 3 taken 617 times.
1704 if(should_check_for_state_things && game->maps[mi]&(1<<i))
6011 {
6012 1087 base_scr->door[i]=dBOMBED;
6013 1087 }
6014
6015 1704 break;
6016 }
6017
6018 46076 update_door(base_scr, i, base_scr->door[i]);
6019
6020
4/4
✓ Branch 0 taken 41512 times.
✓ Branch 1 taken 4564 times.
✓ Branch 2 taken 736 times.
✓ Branch 3 taken 40776 times.
46076 if(door==dSHUTTER||door==d1WAYSHUTTER)
6021 {
6022 5300 base_scr->door[i]=door;
6023 5300 }
6024 46076 }
6025 11519 }
6026
6027
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 36968 times.
37105 if (!(base_scr->flags3 & fCYCLEONINIT))
6028 36968 return;
6029
6030
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 959 times.
1096 for (int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6031 {
6032
4/4
✓ Branch 0 taken 822 times.
✓ Branch 1 taken 137 times.
✓ Branch 2 taken 377 times.
✓ Branch 3 taken 445 times.
959 if (j<0 || base_scr->layermap[j] > 0)
6033 {
6034 514 mapscr* layer_scr = get_scr_layer(screen, j + 1);
6035
3/4
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 137 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 377 times.
514 mapscr* layerscreen= (j<0 ? base_scr : layer_scr->valid ? layer_scr :
6036 &TheMaps[(base_scr->layermap[j]-1)*MAPSCRS]+base_scr->layerscreen[j]);
6037
6038
2/2
✓ Branch 0 taken 90464 times.
✓ Branch 1 taken 514 times.
90978 for(int32_t i=0; i<176; ++i)
6039 {
6040 90464 int32_t c=layerscreen->data[i];
6041
6042 // New screen flag: Cycle Combos At Screen Init
6043
5/6
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 90399 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
90464 if(combobuf[c].nextcombo != 0 && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6044 {
6045 65 int32_t r = 0;
6046
6047
4/4
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 65 times.
149 while(combobuf[c].can_cycle() && r++ < 10)
6048 {
6049 84 newcombo const& cmb = combobuf[c];
6050 84 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6052 84 layerscreen->data[i] = cid;
6053
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 69 times.
84 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
69 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6055 84 c = layerscreen->data[i];
6056 }
6057 65 }
6058 90464 }
6059 514 }
6060 959 }
6061 37105 }
6062
6063 // Set `cur_screen` to `screen` and load new screens into temporary memory.
6064 //
6065 // Called anytime a player moves to a new screen (either via warping, scrolling, continue, starting
6066 // the game, etc...)
6067 //
6068 // Note: for regions, only the initial screen load calls this function. Simply walking between
6069 // screens in the same region does not use this, because every screen in a region is loaded into
6070 // temporary memory up front.
6071 //
6072 // If scr >= 0x80, `hero_screen` will be saved to `home_screen` and also be loaded into
6073 // `special_warp_return_scr`.
6074 //
6075 // If origin_screen_overlay is true, the old origin_scr combos will be copied to the new origin_scr combos
6076 // on all layers (but only where the new screen has a 0 combo).
6077 //
6078 // TODO: loadscr should set curdmap, but currently callers do that.
6079 35861 void loadscr(int32_t destdmap, int32_t screen, int32_t ldir, bool origin_screen_overlay, bool no_x80_dir)
6080 {
6081 35861 zapp_reporting_set_tag("screen", screen);
6082
2/2
✓ Branch 0 taken 8927 times.
✓ Branch 1 taken 26934 times.
35861 if (destdmap != -1)
6083 8927 zapp_reporting_set_tag("dmap", destdmap);
6084
6085 35861 int32_t orig_destdmap = destdmap;
6086
2/2
✓ Branch 0 taken 8927 times.
✓ Branch 1 taken 26934 times.
35861 if (destdmap < 0) destdmap = cur_dmap;
6087
6088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35861 times.
35861 if (replay_is_active())
6089 {
6090
1/2
✓ Branch 0 taken 35861 times.
✗ Branch 1 not taken.
35861 if (replay_get_mode() == ReplayMode::ManualTakeover)
6091 replay_stop_manual_takeover();
6092
6093
2/2
✓ Branch 0 taken 26934 times.
✓ Branch 1 taken 8927 times.
35861 if (orig_destdmap != -1)
6094 {
6095
2/2
✓ Branch 0 taken 7854 times.
✓ Branch 1 taken 1073 times.
8927 if (strlen(DMaps[orig_destdmap].name) > 0)
6096 {
6097
1/2
✓ Branch 0 taken 7854 times.
✗ Branch 1 not taken.
7854 replay_step_comment(fmt::format("dmap={} {}", orig_destdmap, DMaps[orig_destdmap].name));
6098 7854 }
6099 else
6100 {
6101
1/2
✓ Branch 0 taken 1073 times.
✗ Branch 1 not taken.
1073 replay_step_comment(fmt::format("dmap={}", orig_destdmap));
6102 }
6103 8927 }
6104 35861 replay_step_comment_loadscr(screen);
6105
6106 // Reset the rngs and frame count so that recording steps can be modified without impacting
6107 // behavior of later screens.
6108 35861 replay_sync_rng();
6109 35861 }
6110
6111
2/2
✓ Branch 0 taken 1707527 times.
✓ Branch 1 taken 35861 times.
1743388 for (auto& state : get_screen_states())
6112 1707527 state.second.triggered_secrets = false;
6113 35861 slopes.clear();
6114 35861 Hero.clear_platform_ffc();
6115 35861 timeExitAllGenscript(GENSCR_ST_CHANGE_SCREEN);
6116 35861 clear_darkroom_bitmaps();
6117 35861 msgscr = nullptr;
6118
6119
2/2
✓ Branch 0 taken 50400494 times.
✓ Branch 1 taken 35861 times.
50436355 for (word x=0; x<animated_combos; x++)
6120 {
6121
2/2
✓ Branch 0 taken 20920158 times.
✓ Branch 1 taken 29480336 times.
50400494 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6122 {
6123 20920158 combobuf[animated_combo_table4[x][0]].aclk = 0;
6124 20920158 }
6125 50400494 }
6126 35861 reset_combo_animations2();
6127 35861 region_is_lit = false;
6128
6129 // Legacy features (combo and ffc overlays) may need the previous origin screens during loading
6130 // of the new ones.
6131 35861 bool origin_ffc_overlay = false;
6132
2/2
✓ Branch 0 taken 34723 times.
✓ Branch 1 taken 1138 times.
35861 if (origin_scr)
6133 {
6134
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 34721 times.
34723 if (!(origin_scr->flags5&fNOFFCARRYOVER))
6135 {
6136 34721 int c = origin_scr->numFFC();
6137
2/2
✓ Branch 0 taken 34577 times.
✓ Branch 1 taken 1038847 times.
1073424 for (int i = 0; i < c; i++)
6138 {
6139
2/2
✓ Branch 0 taken 1038703 times.
✓ Branch 1 taken 144 times.
1038847 if (origin_scr->ffcs[i].flags&ffc_carryover)
6140 {
6141 144 origin_ffc_overlay = true;
6142 144 break;
6143 }
6144 1038703 }
6145 34721 }
6146
6147
3/4
✓ Branch 0 taken 34723 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✓ Branch 3 taken 34579 times.
34723 if (origin_screen_overlay || origin_ffc_overlay)
6148 {
6149
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 144 times.
1152 for (int i = 0; i <= 6; i++)
6150 {
6151 1008 mapscr* prev_scr = get_scr_layer(cur_screen, i);
6152
1/2
✓ Branch 0 taken 1008 times.
✗ Branch 1 not taken.
1008 if (prev_scr)
6153 1008 prev_origin_scrs[i] = *prev_scr;
6154 else
6155 prev_origin_scrs[i] = {};
6156 1008 }
6157 144 }
6158 34723 }
6159
6160 // Based on origin_ffc_overlay, some ffc scripts don't get reset. This set starts with all of
6161 // them, but scripts that need their data to persist will be removed.
6162 35861 loadscr_ffc_script_ids_to_remove.clear();
6163
2/2
✓ Branch 0 taken 74705630 times.
✓ Branch 1 taken 35861 times.
74741491 for (auto& key : scriptEngineDatas | std::views::keys)
6164 {
6165
2/2
✓ Branch 0 taken 73583757 times.
✓ Branch 1 taken 1121873 times.
74705630 if (key.first == ScriptType::FFC)
6166 1121873 loadscr_ffc_script_ids_to_remove.insert(key.second);
6167 }
6168
6169 35861 load_region(destdmap, screen);
6170
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 34954 times.
35861 home_screen = screen >= 0x80 ? hero_screen : cur_screen;
6171 35861 hero_screen = screen;
6172
6173 35861 cpos_clear_all();
6174 35861 FFCore.destroyScriptableObjectsOfType(ScriptType::Screen);
6175 35861 FFCore.clear_combo_scripts();
6176
6177
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35697 times.
35861 if (is_in_scrolling_region())
6178 {
6179
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6180 {
6181
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6182 {
6183
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool screen_overlay = origin_screen_overlay && screen == cur_screen;
6184
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool ffc_overlay = origin_ffc_overlay && screen == cur_screen;
6185 1408 load_a_screen_and_layers_init(destdmap, screen, ldir, screen_overlay, ffc_overlay);
6186 1408 }
6187 20992 }
6188 164 }
6189 else
6190 {
6191 35697 load_a_screen_and_layers_init(destdmap, screen, ldir, origin_screen_overlay, origin_ffc_overlay);
6192 }
6193
6194 35861 prepare_current_region_handles();
6195
6196
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35697 times.
35861 if (is_in_scrolling_region())
6197 {
6198
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6199 {
6200
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6201 {
6202 1408 load_a_screen_and_layers_post(destdmap, screen, ldir);
6203 1408 }
6204 20992 }
6205 164 }
6206 else
6207 {
6208 35697 load_a_screen_and_layers_post(destdmap, screen, ldir);
6209 }
6210
6211 // If on a special screen, load the screen the player is currently on (home_screen) into special_warp_return_scr.
6212
2/2
✓ Branch 0 taken 34954 times.
✓ Branch 1 taken 907 times.
35861 if (screen >= 0x80)
6213
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 431 times.
907 loadscr_old(orig_destdmap, home_screen, no_x80_dir ? -1 : ldir, origin_screen_overlay);
6214
6215 35861 update_slope_comboposes();
6216 35861 cpos_force_update();
6217 35861 trig_trigger_groups();
6218
6219
2/2
✓ Branch 0 taken 1121599 times.
✓ Branch 1 taken 35861 times.
1157460 for (int index : loadscr_ffc_script_ids_to_remove)
6220 {
6221 1121599 FFCore.destroyScriptableObject(ScriptType::FFC, index);
6222 }
6223
6224 // "extended height mode" includes the top 56 pixels as part of the visible mapscr viewport,
6225 // allowing for regions to display 4 more rows of combos (as many as ALTTP does). This part of
6226 // screen is normally reserved for the passive subscreen, but in this mode mapscr combos are drawn below it.
6227 // It is up to the quest designer to make their subscreen be actually transparent.
6228 //
6229 // When not in "extended height mode" (otherwise 56 is 0):
6230 // - playing_field_offset: 56, but changes during earthquakes
6231 // - original_playing_field_offset: always 56
6232 //
6233 // These values are used to adjust where things are drawn on screen to account for the passive subscreen. Examples:
6234 // - yofs of sprites
6235 // - bitmap y offsets in draw_screen
6236 // - drawing offsets for putscr, do_layer
6237 // - drawing offsets for various calls to overtile16 (see bomb weapon explosion)
6238 // - lots more
6239 //
6240 // TODO: consider refactor of yofs, make yofs start as 0 by default and add playing_field_offset at draw time?
6241
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 35719 times.
35861 if (is_extended_height_mode())
6242 {
6243 142 playing_field_offset = 0;
6244 142 original_playing_field_offset = 0;
6245 // A few sprites exist as globals, so we must manually reset them.
6246 142 Hero.yofs = 0;
6247 142 mblock2.yofs = 0;
6248 142 }
6249 else
6250 {
6251 35719 mblock2.yofs = Hero.yofs = playing_field_offset = 56;
6252 35719 original_playing_field_offset = 56;
6253 }
6254 35861 is_any_room_dark = is_any_dark();
6255
6256 35861 game->load_portal();
6257 35861 throwGenScriptEvent(GENSCR_EVENT_CHANGE_SCREEN);
6258
3/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 35826 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
35861 if (Hero.lift_wpn && get_qr(qr_CARRYABLE_NO_ACROSS_SCREEN))
6259 {
6260 delete Hero.lift_wpn;
6261 Hero.lift_wpn = nullptr;
6262 }
6263
6264 35861 enemy_spawning_has_checked_been_here = false;
6265 35861 markBmap(-1, hero_screen);
6266 35861 Hero.maybe_begin_advanced_maze();
6267 35861 }
6268
6269 // Don't use this directly! Use `loadscr` instead.
6270 907 void loadscr_old(int32_t destdmap, int32_t screen,int32_t ldir,bool overlay)
6271 {
6272
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 int32_t destlvl = DMaps[destdmap < 0 ? cur_dmap : destdmap].level;
6273
6274 907 mapscr previous_scr = *special_warp_return_scr;
6275 907 mapscr* scr = special_warp_return_scr;
6276
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 const mapscr* source = get_canonical_scr(cur_map, screen);
6277
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 *scr = *source;
6278
6279
2/2
✓ Branch 0 taken 5442 times.
✓ Branch 1 taken 907 times.
6349 for (int i = 1; i <= 6; i++)
6280 {
6281
2/2
✓ Branch 0 taken 383 times.
✓ Branch 1 taken 5059 times.
5442 if (scr->layermap[i-1] > 0)
6282
2/4
✓ Branch 0 taken 383 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 383 times.
✗ Branch 3 not taken.
383 special_warp_return_scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6283 else
6284 5059 special_warp_return_scrs[i] = {};
6285 5442 }
6286
6287 907 scr->valid |= mVALID; //layer 0 is always valid
6288
6289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 907 times.
907 if ( source->script > 0 )
6290 {
6291 scr->script = source->script;
6292 for ( int32_t q = 0; q < 8; q++ )
6293 {
6294 scr->screeninitd[q] = source->screeninitd[q];
6295 }
6296 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
6297 }
6298 else
6299 {
6300 907 scr->script = 0;
6301 }
6302
6303
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 if(overlay)
6304 {
6305 for(int32_t c=0; c< 176; ++c)
6306 {
6307 if(scr->data[c]==0)
6308 {
6309 scr->data[c]=previous_scr.data[c];
6310 scr->sflag[c]=previous_scr.sflag[c];
6311 scr->cset[c]=previous_scr.cset[c];
6312 }
6313 }
6314
6315 for(int32_t i=0; i<6; i++)
6316 {
6317 if(previous_scr.layermap[i]>0 && scr->layermap[i]>0)
6318 {
6319 int32_t lm = (scr->layermap[i]-1)*MAPSCRS+scr->layerscreen[i];
6320 int32_t fm = (previous_scr.layermap[i]-1)*MAPSCRS+previous_scr.layerscreen[i];
6321
6322 for(int32_t c=0; c< 176; ++c)
6323 {
6324 if(TheMaps[lm].data[c]==0)
6325 {
6326 TheMaps[lm].data[c] = TheMaps[fm].data[c];
6327 TheMaps[lm].sflag[c] = TheMaps[fm].sflag[c];
6328 TheMaps[lm].cset[c] = TheMaps[fm].cset[c];
6329 }
6330 }
6331 }
6332 }
6333 }
6334
6335
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
29900 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
6336
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 int c = scr->numFFC();
6337
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 28993 times.
29900 for (word i = 0; i < c; i++)
6338 {
6339 28993 scr->ffcs[i].screen_spawned = screen;
6340
1/2
✓ Branch 0 taken 28993 times.
✗ Branch 1 not taken.
28993 scr->ffcs[i].x += offx;
6341
1/2
✓ Branch 0 taken 28993 times.
✗ Branch 1 not taken.
28993 scr->ffcs[i].y += offy;
6342 28993 }
6343
6344 907 int mi = mapind(cur_map, screen);
6345
6346 // Apply perm secrets, if applicable.
6347
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 536 times.
✓ Branch 3 taken 371 times.
907 if(canPermSecret(destdmap,screen))
6348 {
6349
3/4
✓ Branch 0 taken 536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 204 times.
✓ Branch 3 taken 332 times.
536 if(game->maps[mi]&mSECRET) // if special stuff done before
6350 {
6351
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 reveal_hidden_stairs(scr, screen, false);
6352
6353
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
6354
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 get_screen_state(special_warp_return_scr->screen).triggered_secrets = true;
6355 204 bool do_replay_comment = true;
6356 204 bool from_active_screen = false;
6357
2/4
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 204 times.
✗ Branch 3 not taken.
204 trigger_secrets_for_screen_internal(create_screen_handles(special_warp_return_scr), from_active_screen, false, -1, do_replay_comment);
6358 204 }
6359
2/4
✓ Branch 0 taken 536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 536 times.
✗ Branch 3 not taken.
536 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6360 {
6361 for (int layer = 0; layer <= 6; layer++)
6362 {
6363 mapscr* tscr = &special_warp_return_scrs[layer];
6364 for (int pos = 0; pos < 176; pos++)
6365 {
6366 newcombo const* cmb = &combobuf[tscr->data[pos]];
6367 if(cmb->type == cLIGHTTARGET)
6368 {
6369 if(!(cmb->usrflags&cflag1)) //Unlit version
6370 {
6371 tscr->data[pos] += 1;
6372 }
6373 }
6374 }
6375 }
6376 }
6377 536 }
6378
6379 screen_handles_t screen_handles;
6380
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 6349 times.
7256 for (int i = 0; i <= 6; i++)
6381
3/4
✓ Branch 0 taken 6349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1289 times.
✓ Branch 3 taken 5060 times.
6349 screen_handles[i] = {scr, special_warp_return_scrs[i].is_valid() ? &special_warp_return_scrs[i] : nullptr, screen, i};
6382
6383
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 907 times.
✗ Branch 3 not taken.
907 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
6384
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 toggle_gswitches_load(screen_handles);
6385
6386
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 902 times.
907 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6387 {
6388
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 remove_lockblocks(screen_handles);
6389 5 }
6390
6391
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 906 times.
907 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6392 {
6393
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6394 1 }
6395
6396
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mCHEST) // if special stuff done before
6397 {
6398 remove_chests(screen_handles);
6399 }
6400
6401
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6402 {
6403 remove_lockedchests(screen_handles);
6404 }
6405
6406
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6407 {
6408 remove_bosschests(screen_handles);
6409 }
6410
6411
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 clear_xdoors(screen_handles, true);
6412
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 clear_xstatecombos(screen_handles, true);
6413
6414 // check doors
6415
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 371 times.
✓ Branch 3 taken 536 times.
907 if (isdungeon(destdmap, screen))
6416 {
6417
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 371 times.
1855 for(int32_t i=0; i<4; i++)
6418 {
6419 1484 int32_t door=scr->door[i];
6420
6421
4/4
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 89 times.
✓ Branch 3 taken 1295 times.
1484 switch(door)
6422 {
6423 case d1WAYSHUTTER:
6424 case dSHUTTER:
6425
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1295 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1295 if ((ldir^1)==i && screen == home_screen)
6426 {
6427 scr->door[i]=dOPENSHUTTER;
6428 }
6429
6430
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 1190 times.
1295 get_screen_state(screen).open_doors = -4;
6431 105 break;
6432
6433 case dLOCKED:
6434
3/4
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 11 times.
91 if(game->maps[mi]&(1<<i))
6435 {
6436 80 scr->door[i]=dUNLOCKED;
6437 80 }
6438
6439 91 break;
6440
6441 case dBOSS:
6442
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 4 times.
9 if(game->maps[mi]&(1<<i))
6443 {
6444 5 scr->door[i]=dOPENBOSS;
6445 5 }
6446
6447 9 break;
6448
6449 case dBOMB:
6450
3/4
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 38 times.
89 if(game->maps[mi]&(1<<i))
6451 {
6452 51 scr->door[i]=dBOMBED;
6453 51 }
6454
6455 89 break;
6456 }
6457
6458
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 1190 times.
294 update_door(scr, i, scr->door[i]);
6459
6460
4/4
✓ Branch 0 taken 1390 times.
✓ Branch 1 taken 94 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1379 times.
1484 if(door==dSHUTTER||door==d1WAYSHUTTER)
6461 {
6462 105 scr->door[i]=door;
6463 105 }
6464 1484 }
6465 371 }
6466
6467
2/2
✓ Branch 0 taken 6915 times.
✓ Branch 1 taken 731 times.
7256 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6468 {
6469
4/4
✓ Branch 0 taken 5442 times.
✓ Branch 1 taken 1473 times.
✓ Branch 2 taken 2763 times.
✓ Branch 3 taken 2679 times.
6915 if (j<0 || scr->layermap[j] > 0)
6470 {
6471
4/4
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 383 times.
✓ Branch 2 taken 382 times.
✓ Branch 3 taken 1 times.
4236 mapscr *layerscreen= (j<0 ? scr : special_warp_return_scrs[j+1].valid ? &special_warp_return_scrs[j+1] :
6472 1 &TheMaps[(scr->layermap[j]-1)*MAPSCRS]+scr->layerscreen[j]);
6473
6474
2/2
✓ Branch 0 taken 224660 times.
✓ Branch 1 taken 3670 times.
228330 for(int32_t i=0; i<176; ++i)
6475 {
6476 224660 int32_t c=layerscreen->data[i];
6477
6478 // New screen flag: Cycle Combos At Screen Init
6479
5/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 224654 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2380 times.
✓ Branch 7 taken 2380 times.
224660 if(combobuf[c].nextcombo != 0 && (scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6480 {
6481 2380 int32_t r = 0;
6482
6483
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2380 while(combobuf[c].can_cycle() && r++ < 10)
6484 {
6485 newcombo const& cmb = combobuf[c];
6486 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6487 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6488 layerscreen->data[i] = cid;
6489 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6490 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6491 c = layerscreen->data[i];
6492 }
6493 }
6494 227040 }
6495 3670 }
6496 6349 }
6497 5491 }
6498
6499 // Load screen (and layers). Unlike loadscr, this doesn't load to the global temporary_screens, but
6500 // instead returns an array of mapscr.
6501 // Used to draw/save the map.
6502 45680 std::array<mapscr, 7> loadscr2(int32_t screen)
6503 {
6504 45680 std::array<mapscr, 7> scrs;
6505 45680 mapscr* scr = &scrs[0];
6506
6507
2/2
✓ Branch 0 taken 64716181 times.
✓ Branch 1 taken 45680 times.
64761861 for(word x=0; x<animated_combos; x++)
6508 {
6509
2/2
✓ Branch 0 taken 31963685 times.
✓ Branch 1 taken 32752496 times.
64716181 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6510 {
6511 32752496 combobuf[animated_combo_table4[x][0]].aclk=0;
6512 32752496 }
6513 64716181 }
6514
6515
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 const mapscr* source = get_canonical_scr(cur_map, screen);
6516
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!source->is_valid())
6517 {
6518 scrs[0].valid = 0;
6519 return scrs;
6520 }
6521
6522
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 *scr = *get_canonical_scr(cur_map, screen);
6523
2/2
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
319760 for (int i = 1; i <= 6; i++)
6524 {
6525
2/2
✓ Branch 0 taken 64814 times.
✓ Branch 1 taken 209266 times.
274080 if (scr->layermap[i-1] > 0)
6526
2/4
✓ Branch 0 taken 64814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64814 times.
✗ Branch 3 not taken.
64814 scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6527 else
6528 209266 scrs[i] = {};
6529 274080 }
6530
6531 screen_handles_t screen_handles;
6532
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i < 7; i++)
6533
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103790 times.
✓ Branch 3 taken 215970 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
6534
6535 45680 int mi = mapind(cur_map, screen);
6536
6537
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45626 times.
✓ Branch 3 taken 54 times.
45680 if(canPermSecret(-1,screen))
6538 {
6539
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5730 times.
✓ Branch 3 taken 39896 times.
45626 if(game->maps[mi]&mSECRET) // if special stuff done before
6540 {
6541
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 reveal_hidden_stairs(scr, screen, false);
6542 5730 bool from_active_screen = false;
6543 5730 bool do_replay_comment = true;
6544
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 trigger_secrets_for_screen_internal(screen_handles, from_active_screen, false, -1, do_replay_comment);
6545 5730 }
6546
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45609 times.
✓ Branch 3 taken 17 times.
45626 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6547 {
6548
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 17 times.
136 for (int layer = 0; layer <= 6; layer++)
6549 {
6550 119 mapscr* tscr = &scrs[layer];
6551
2/2
✓ Branch 0 taken 20944 times.
✓ Branch 1 taken 119 times.
21063 for (int pos = 0; pos < 176; pos++)
6552 {
6553 20944 newcombo const* cmb = &combobuf[tscr->data[pos]];
6554
2/2
✓ Branch 0 taken 20927 times.
✓ Branch 1 taken 17 times.
20944 if(cmb->type == cLIGHTTARGET)
6555 {
6556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if(!(cmb->usrflags&cflag1)) //Unlit version
6557 {
6558 17 tscr->data[pos] += 1;
6559 17 }
6560 17 }
6561 20944 }
6562 119 }
6563 17 }
6564 45626 }
6565
6566
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 233 times.
✓ Branch 3 taken 45447 times.
45680 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6567 {
6568
1/2
✓ Branch 0 taken 233 times.
✗ Branch 1 not taken.
233 remove_lockblocks(screen_handles);
6569 233 }
6570
6571
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 45679 times.
45680 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6572 {
6573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6574 1 }
6575
6576
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
✓ Branch 3 taken 45579 times.
45680 if(game->maps[mi]&mCHEST) // if special stuff done before
6577 {
6578
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 remove_chests(screen_handles);
6579 101 }
6580
6581
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 45656 times.
45680 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6582 {
6583
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 remove_lockedchests(screen_handles);
6584 24 }
6585
6586
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6587 {
6588 remove_bosschests(screen_handles);
6589 }
6590
6591
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xdoors(screen_handles);
6592
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xstatecombos(screen_handles);
6593
6594 // check doors
6595
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 45626 times.
45680 if (isdungeon(screen))
6596 {
6597
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 54 times.
270 for(int32_t i=0; i<4; i++)
6598 {
6599 216 int32_t door=scr->door[i];
6600 216 bool putit=true;
6601
6602
4/5
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 61 times.
✓ Branch 4 taken 139 times.
216 switch(door)
6603 {
6604 case d1WAYSHUTTER:
6605 case dSHUTTER:
6606 61 break;
6607
6608 case dLOCKED:
6609
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if(game->maps[mi]&(1<<i))
6610 {
6611 12 scr->door[i]=dUNLOCKED;
6612 12 }
6613
6614 12 break;
6615
6616 case dBOSS:
6617
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if(game->maps[mi]&(1<<i))
6618 {
6619 scr->door[i]=dOPENBOSS;
6620 }
6621
6622 4 break;
6623
6624 case dBOMB:
6625 if(game->maps[mi]&(1<<i))
6626 {
6627 scr->door[i]=dBOMBED;
6628 }
6629
6630 break;
6631 }
6632
6633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if(putit)
6634 {
6635
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 putdoor(scr, scrollbuf, i, scr->door[i], false);
6636 216 }
6637
6638
3/4
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 61 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 155 times.
216 if(door==dSHUTTER||door==d1WAYSHUTTER)
6639 {
6640 61 scr->door[i]=door;
6641 61 }
6642 216 }
6643 54 }
6644
6645
2/2
✓ Branch 0 taken 319760 times.
✓ Branch 1 taken 45680 times.
365440 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6646 {
6647
4/4
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
✓ Branch 2 taken 64814 times.
✓ Branch 3 taken 209266 times.
319760 if (j < 0 || scr->layermap[j] > 0)
6648 {
6649
2/2
✓ Branch 0 taken 64814 times.
✓ Branch 1 taken 45680 times.
110494 mapscr *layerscreen= (j<0 ? scr
6650 64814 : &(TheMaps[(scr->layermap[j]-1)*MAPSCRS+scr->layerscreen[j]]));
6651
6652
2/2
✓ Branch 0 taken 19446944 times.
✓ Branch 1 taken 110494 times.
19557438 for(int32_t i=0; i<176; ++i)
6653 {
6654 19446944 int32_t c=layerscreen->data[i];
6655
6656 // New screen flag: Cycle Combos At Screen Init
6657
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19446944 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
19446944 if((scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6658 {
6659 int32_t r = 0;
6660
6661 while(combobuf[c].can_cycle() && r++ < 10)
6662 {
6663 newcombo const& cmb = combobuf[c];
6664 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6665 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6666 layerscreen->data[i] = cid;
6667 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6668 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6669 c = layerscreen->data[i];
6670 }
6671 }
6672 19446944 }
6673 110494 }
6674 319760 }
6675
6676 45680 return scrs;
6677
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 }
6678
6679 19019391 void putscr(mapscr* scr, BITMAP* dest, int32_t x, int32_t y)
6680 {
6681 // This is a bogus value while screenscrolling == true, but that's ok
6682 // because it is only used to calculate the rpos, and during screenscrolling
6683 // only the modulus to get pos (draw_cmb_pos does RPOS_TO_POS) is needed, which
6684 // is always the same no matter the value of scr.
6685 19019391 int screen = get_screen_for_world_xy(x, y);
6686
6687 19019391 x -= viewport.x;
6688 19019391 y -= viewport.y;
6689
6690
3/6
✓ Branch 0 taken 19019391 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19019391 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19019391 times.
19019391 if (!scr->is_valid()||!show_layers[0]||scr->hidelayers & 1)
6691 {
6692 rectfill(dest,x,y,x+255,y+175,0);
6693 return;
6694 }
6695
6696 37909872 bool over = XOR(scr->flags7&fLAYER2BG,DMaps[cur_dmap].flags&dmfLAYER2BG)
6697
2/2
✓ Branch 0 taken 128910 times.
✓ Branch 1 taken 18890481 times.
19019391 || XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG);
6698
6699 int start_x, end_x, start_y, end_y;
6700 19019391 get_bounds_for_draw_cmb_calls(dest, x, y, start_x, end_x, start_y, end_y);
6701
2/2
✓ Branch 0 taken 19019391 times.
✓ Branch 1 taken 202588028 times.
221607419 for (int cy = start_y; cy < end_y; cy++)
6702 {
6703
2/2
✓ Branch 0 taken 3076314498 times.
✓ Branch 1 taken 202588028 times.
3278902526 for (int cx = start_x; cx < end_x; cx++)
6704 {
6705 3076314498 int i = cx + cy*16;
6706
2/2
✓ Branch 0 taken 357938374 times.
✓ Branch 1 taken 2718376124 times.
3076314498 auto rpos = screenscrolling ? rpos_t::None : POS_TO_RPOS(i, screen);
6707 3076314498 draw_cmb_pos(dest, x + cx*16, y + cy*16, rpos, scr->data[i], scr->cset[i], 0, over, false);
6708 3076314498 }
6709 202588028 }
6710 19019391 }
6711
6712 15541981 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y)
6713 {
6714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15541981 times.
15541981 if (!show_layers[0])
6715 {
6716 return;
6717 }
6718
6719 15541981 x -= viewport.x;
6720 15541981 y -= viewport.y;
6721
6722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15541981 times.
31220280 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
6723 15678299 mapscr* scr = screen_handles[0].base_scr;
6724
1/2
✓ Branch 0 taken 15678299 times.
✗ Branch 1 not taken.
15678299 if (!scr->is_valid())
6725 return;
6726
6727
2/2
✓ Branch 0 taken 123411 times.
✓ Branch 1 taken 15554888 times.
15678299 if(scr->door[0]==dBOMBED)
6728 {
6729 123411 over_door(scr, dest, 39, up, offx+x, offy+y);
6730 123411 }
6731
6732
2/2
✓ Branch 0 taken 143109 times.
✓ Branch 1 taken 15535190 times.
15678299 if(scr->door[1]==dBOMBED)
6733 {
6734 143109 over_door(scr, dest, 135, down, offx+x, offy+y);
6735 143109 }
6736
6737
2/2
✓ Branch 0 taken 155862 times.
✓ Branch 1 taken 15522437 times.
15678299 if(scr->door[2]==dBOMBED)
6738 {
6739 155862 over_door(scr, dest, 66, left, offx+x, offy+y);
6740 155862 }
6741
6742
2/2
✓ Branch 0 taken 132289 times.
✓ Branch 1 taken 15546010 times.
15678299 if(scr->door[3]==dBOMBED)
6743 {
6744 132289 over_door(scr, dest, 77, right, offx+x, offy+y);
6745 132289 }
6746 15678299 });
6747 15541981 }
6748
6749 3341092 void putscrdoors(mapscr* scr, BITMAP *dest, int32_t x, int32_t y)
6750 {
6751
2/4
✓ Branch 0 taken 3341092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3341092 times.
✗ Branch 3 not taken.
3341092 if (!scr->is_valid() || !show_layers[0])
6752 return;
6753
6754 3341092 x -= viewport.x;
6755 3341092 y -= viewport.y;
6756
6757
2/2
✓ Branch 0 taken 37656 times.
✓ Branch 1 taken 3303436 times.
3341092 if(scr->door[0]==dBOMBED)
6758 {
6759 37656 over_door(scr,dest,39,up,x,y);
6760 37656 }
6761
6762
2/2
✓ Branch 0 taken 36495 times.
✓ Branch 1 taken 3304597 times.
3341092 if(scr->door[1]==dBOMBED)
6763 {
6764 36495 over_door(scr,dest,135,down,x,y);
6765 36495 }
6766
6767
2/2
✓ Branch 0 taken 40440 times.
✓ Branch 1 taken 3300652 times.
3341092 if(scr->door[2]==dBOMBED)
6768 {
6769 40440 over_door(scr,dest,66,left,x,y);
6770 40440 }
6771
6772
2/2
✓ Branch 0 taken 37063 times.
✓ Branch 1 taken 3304029 times.
3341092 if(scr->door[3]==dBOMBED)
6773 {
6774 37063 over_door(scr,dest,77,right,x,y);
6775 37063 }
6776 3341092 }
6777 232732448 static inline bool standing_on_z(newcombo const& cmb, zfix const& standing_z_state)
6778 {
6779 232732448 zfix cmb_z, cmb_z_step;
6780
4/4
✓ Branch 0 taken 104218 times.
✓ Branch 1 taken 232628230 times.
✓ Branch 2 taken 88819 times.
✓ Branch 3 taken 15399 times.
232732448 if(cmb.type == cCSWITCHBLOCK && (cmb.usrflags & cflag9))
6781 {
6782 15399 cmb_z = zslongToFix(cmb.attributes[2]);
6783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15399 times.
15399 cmb_z_step = zslongToFix(zc_max(0,cmb.attributes[3]));
6784 15399 }
6785
2/2
✓ Branch 0 taken 43752 times.
✓ Branch 1 taken 232673297 times.
232717049 else if(cmb.genflags & cflag3)
6786 {
6787 43752 cmb_z = cmb.z_height;
6788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43752 times.
43752 cmb_z_step = zc_max(0_zf,cmb.z_step_height);
6789 43752 }
6790 232673297 else return false;
6791
6792
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 59151 times.
✓ Branch 2 taken 58002 times.
✓ Branch 3 taken 1149 times.
59151 return (standing_z_state < 0 || (cmb_z>0 && (cmb_z - cmb_z_step) <= standing_z_state));
6793 232732448 }
6794 56070409 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt)
6795 {
6796 56070409 return _walkflag(zx,zy,cnt,0_zf);
6797 }
6798
6799 133012645 bool _walkflag_new(const mapscr* s0, const mapscr* s1, const mapscr* s2, zfix_round zx, zfix_round zy, zfix const& standing_z_state, bool is_temp_screens)
6800 {
6801 133012645 int x = zx.getRound(), y = zy.getRound();
6802 133012645 int pos = COMBOPOS(x % 256, y % 176);
6803 133012645 const newcombo& c = combobuf[s0->data[pos]];
6804 133012645 const newcombo& c1 = combobuf[s1->data[pos]];
6805 133012645 const newcombo& c2 = combobuf[s2->data[pos]];
6806
4/4
✓ Branch 0 taken 131017204 times.
✓ Branch 1 taken 1995441 times.
✓ Branch 2 taken 131007744 times.
✓ Branch 3 taken 9460 times.
266227578 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
6807
4/4
✓ Branch 0 taken 101153 times.
✓ Branch 1 taken 131108879 times.
✓ Branch 2 taken 2101809 times.
✓ Branch 3 taken 4245 times.
133012645 (iswater_type(c2.type))) && DRIEDLAKE);
6808 133214933 int32_t b=1;
6809
2/2
✓ Branch 0 taken 65698247 times.
✓ Branch 1 taken 67516686 times.
133214933 if(x&8) b<<=2;
6810
2/2
✓ Branch 0 taken 62223907 times.
✓ Branch 1 taken 70991026 times.
133214933 if(y&8) b<<=1;
6811
6812 133214933 int32_t cwalkflag = c.walk;
6813
3/4
✓ Branch 0 taken 133113789 times.
✓ Branch 1 taken 101144 times.
✓ Branch 2 taken 133113789 times.
✗ Branch 3 not taken.
133214933 if(is_temp_screens && standing_on_z(c,standing_z_state)) cwalkflag &= (c.walk>>4)^0xF;
6814
8/10
✓ Branch 0 taken 50572 times.
✓ Branch 1 taken 133164361 times.
✓ Branch 2 taken 2096585 times.
✓ Branch 3 taken 2046013 times.
✓ Branch 4 taken 2096585 times.
✓ Branch 5 taken 133113789 times.
✓ Branch 6 taken 2096585 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2096585 times.
✗ Branch 9 not taken.
133214933 else if ((c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) || (iswater_type(c.type) && ((c.walk>>4)&b) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
6815
2/2
✓ Branch 0 taken 63467387 times.
✓ Branch 1 taken 69646402 times.
133113789 if (s1 != s0)
6816 {
6817
3/4
✓ Branch 0 taken 69646402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69645716 times.
✓ Branch 3 taken 686 times.
69646402 if(is_temp_screens && standing_on_z(c1,standing_z_state)) cwalkflag &= (c1.walk>>4)^0xF;
6818
4/10
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69633987 times.
✓ Branch 2 taken 11729 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11729 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
69645716 else if ((iswater_type(c1.type) && ((c1.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_1) && !((c1.usrflags&cflag3) || (c1.usrflags&cflag4)))) cwalkflag &= c1.walk;
6819
2/2
✓ Branch 0 taken 62906 times.
✓ Branch 1 taken 69582810 times.
69645716 else if (c1.type == cBRIDGE)
6820 {
6821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62906 times.
62906 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
6822 {
6823 62906 int efflag = (c1.walk & 0xF0)>>4;
6824 62906 int newsolid = (c1.walk & 0xF);
6825 62906 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
6826 62906 }
6827 else cwalkflag &= c1.walk;
6828 62906 }
6829
3/8
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69571081 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11729 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
69582810 else if ((iswater_type(c1.type) && get_qr(qr_WATER_ON_LAYER_1) && ((c1.usrflags&cflag3) || (c1.usrflags&cflag4)) && ((c1.walk>>4)&b))) cwalkflag = 0;
6830 69582810 else cwalkflag |= c1.walk;
6831 69646402 }
6832
2/2
✓ Branch 0 taken 103141532 times.
✓ Branch 1 taken 29972257 times.
133113789 if (s2 != s0)
6833 {
6834
2/4
✓ Branch 0 taken 29972257 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29972257 times.
✗ Branch 3 not taken.
29972257 if(is_temp_screens && standing_on_z(c2,standing_z_state)) cwalkflag &= (c2.walk>>4)^0xF;
6835
4/10
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 29970103 times.
✓ Branch 2 taken 2154 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2154 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
29972257 else if ((iswater_type(c2.type) && ((c2.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_2) && !((c2.usrflags&cflag3) || (c2.usrflags&cflag4)))) cwalkflag &= c2.walk;
6836
2/2
✓ Branch 0 taken 2982 times.
✓ Branch 1 taken 29969275 times.
29972257 else if (c2.type == cBRIDGE)
6837 {
6838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2982 times.
2982 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
6839 {
6840 2982 int efflag = (c2.walk & 0xF0)>>4;
6841 2982 int newsolid = (c2.walk & 0xF);
6842 2982 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
6843 2982 }
6844 else cwalkflag &= c2.walk;
6845 2982 }
6846
3/8
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 29967121 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2154 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
29969275 else if ((iswater_type(c2.type) && get_qr(qr_WATER_ON_LAYER_2) && ((c2.usrflags&cflag3) || (c2.usrflags&cflag4))) && ((c2.walk>>4)&b)) cwalkflag = 0;
6847 29969275 else cwalkflag |= c2.walk;
6848 29972257 }
6849
6850
4/4
✓ Branch 0 taken 29683517 times.
✓ Branch 1 taken 103430272 times.
✓ Branch 2 taken 948 times.
✓ Branch 3 taken 29682569 times.
133113789 if((cwalkflag&b) && !dried)
6851 29682569 return true;
6852
6853
3/4
✓ Branch 0 taken 103431220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103414809 times.
✓ Branch 3 taken 16411 times.
103431220 if (is_temp_screens && collide_object(zx, zy, 0.0001_zf, 0.0001_zf)) return true;
6854
6855 103414809 return false;
6856 133113789 }
6857
6858 // Returns true if the combo at viewport position x,y is solid. Looks at a combo's quadrant walkablity flags.
6859 133113789 static bool _walkflag_new(zfix_round zx, zfix_round zy, zfix const& standing_z_state)
6860 {
6861 133113789 int x = zx.getRound(), y = zy.getRound();
6862 133113789 mapscr* s0 = get_scr_for_world_xy_layer(x, y, 0);
6863 133113789 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
6864 133113789 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
6865
2/2
✓ Branch 0 taken 63467387 times.
✓ Branch 1 taken 69646402 times.
133113789 if (!s1->valid) s1 = s0;
6866
2/2
✓ Branch 0 taken 103141532 times.
✓ Branch 1 taken 29972257 times.
133113789 if (!s2->valid) s2 = s0;
6867 133113789 return _walkflag_new(s0, s1, s2, zx, zy, standing_z_state, true);
6868 }
6869
6870 128672443 bool _walkflag(zfix_round x,zfix_round y,int32_t cnt,zfix const& standing_z_state)
6871 {
6872 128672443 int max_x = world_w;
6873 128672443 int max_y = world_h;
6874
2/2
✓ Branch 0 taken 68638736 times.
✓ Branch 1 taken 60033707 times.
128672443 if (!get_qr(qr_LTTPWALK))
6875 {
6876 60033707 max_x -= 7;
6877 60033707 max_y -= 7;
6878 60033707 }
6879
4/4
✓ Branch 0 taken 128401575 times.
✓ Branch 1 taken 270868 times.
✓ Branch 2 taken 83268 times.
✓ Branch 3 taken 128318307 times.
128672443 if (x < 0 || y < 0) return false;
6880
2/2
✓ Branch 0 taken 322284 times.
✓ Branch 1 taken 127996023 times.
128318307 if (x >= max_x) return false;
6881
3/4
✓ Branch 0 taken 539829 times.
✓ Branch 1 taken 127456194 times.
✓ Branch 2 taken 539829 times.
✗ Branch 3 not taken.
127996023 if (x >= max_x - 8 && cnt == 2) return false;
6882
2/2
✓ Branch 0 taken 127446815 times.
✓ Branch 1 taken 549208 times.
127996023 if (y >= max_y) return false;
6883
6884
4/4
✓ Branch 0 taken 29580821 times.
✓ Branch 1 taken 97865994 times.
✓ Branch 2 taken 92199020 times.
✓ Branch 3 taken 5666974 times.
127446815 return _walkflag_new(x, y, standing_z_state) || (cnt != 1 && _walkflag_new(x + 8, y, standing_z_state));
6885 128672443 }
6886
6887 99192460 static bool effectflag(int32_t x, int32_t y, int32_t layer)
6888 {
6889 99192460 mapscr* s0 = get_scr_for_world_xy(x, y);
6890 99192460 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
6891 99192460 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
6892
2/2
✓ Branch 0 taken 51563892 times.
✓ Branch 1 taken 47628568 times.
99192460 if (!s1->valid) s1 = s0;
6893
2/2
✓ Branch 0 taken 17702157 times.
✓ Branch 1 taken 81490303 times.
99192460 if (!s2->valid) s2 = s0;
6894
6895 99192460 int pos = COMBOPOS(x % 256, y % 176);
6896 99192460 const newcombo& c = combobuf[s0->data[pos]];
6897 99192460 const newcombo& c1 = combobuf[s1->data[pos]];
6898 99192460 const newcombo& c2 = combobuf[s2->data[pos]];
6899
4/4
✓ Branch 0 taken 98265182 times.
✓ Branch 1 taken 927278 times.
✓ Branch 2 taken 98263816 times.
✓ Branch 3 taken 1366 times.
198384920 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
6900
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 98263816 times.
✓ Branch 2 taken 926808 times.
✓ Branch 3 taken 1836 times.
99192460 (iswater_type(c2.type))) && DRIEDLAKE);
6901 99192460 int32_t b=1;
6902
2/2
✓ Branch 0 taken 49897006 times.
✓ Branch 1 taken 49295454 times.
99192460 if(x&8) b<<=2;
6903
2/2
✓ Branch 0 taken 41845886 times.
✓ Branch 1 taken 57346574 times.
99192460 if(y&8) b<<=1;
6904
6905 99192460 int32_t cwalkflag = (c.walk>>4);
6906
2/2
✓ Branch 0 taken 76383949 times.
✓ Branch 1 taken 22808511 times.
99192460 if (layer == 0) cwalkflag = (c1.walk>>4);
6907
2/2
✓ Branch 0 taken 76385329 times.
✓ Branch 1 taken 22807131 times.
99192460 if (layer == 1) cwalkflag = (c2.walk>>4);
6908 //if (c.type == cBRIDGE || (iswater_type(c.type) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
6909
4/4
✓ Branch 0 taken 51563892 times.
✓ Branch 1 taken 47628568 times.
✓ Branch 2 taken 22484135 times.
✓ Branch 3 taken 29079757 times.
99192460 if (s1 != s0 && layer < 0)
6910 {
6911
2/2
✓ Branch 0 taken 22470729 times.
✓ Branch 1 taken 13406 times.
22484135 if (c1.type == cBRIDGE) cwalkflag &= (~(c1.walk>>4));
6912 22484135 }
6913
4/4
✓ Branch 0 taken 17702157 times.
✓ Branch 1 taken 81490303 times.
✓ Branch 2 taken 13126512 times.
✓ Branch 3 taken 4575645 times.
99192460 if (s2 != s0 && layer < 1)
6914 {
6915
2/2
✓ Branch 0 taken 13122260 times.
✓ Branch 1 taken 4252 times.
13126512 if (c2.type == cBRIDGE) cwalkflag &= (~(c2.walk>>4));
6916 13126512 }
6917
6918
2/2
✓ Branch 0 taken 99034814 times.
✓ Branch 1 taken 157646 times.
99192460 return (cwalkflag&b) ? !dried : false;
6919 }
6920
6921 99567344 bool _effectflag(int32_t x,int32_t y,int32_t cnt, int32_t layer, bool notLink)
6922 {
6923 DCHECK(cnt == 0 || cnt == 1);
6924 99567344 int max_x = world_w;
6925 99567344 int max_y = world_h;
6926
3/4
✓ Branch 0 taken 45833063 times.
✓ Branch 1 taken 53734281 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45833063 times.
99567344 if (!get_qr(qr_LTTPWALK) && !notLink)
6927 {
6928 45833063 max_x -= 7;
6929 45833063 max_y -= 7;
6930 45833063 }
6931
4/4
✓ Branch 0 taken 99566591 times.
✓ Branch 1 taken 753 times.
✓ Branch 2 taken 204 times.
✓ Branch 3 taken 99566387 times.
99567344 if (x < 0 || y < 0) return false;
6932
2/2
✓ Branch 0 taken 818 times.
✓ Branch 1 taken 99565569 times.
99566387 if (x >= max_x) return false;
6933
3/4
✓ Branch 0 taken 521834 times.
✓ Branch 1 taken 99043735 times.
✓ Branch 2 taken 521834 times.
✗ Branch 3 not taken.
99565569 if (x >= max_x - 8 && cnt == 2) return false;
6934
2/2
✓ Branch 0 taken 373109 times.
✓ Branch 1 taken 99192460 times.
99565569 if (y >= max_y) return false;
6935
6936
3/4
✓ Branch 0 taken 99034024 times.
✓ Branch 1 taken 158436 times.
✓ Branch 2 taken 158436 times.
✗ Branch 3 not taken.
99192460 return effectflag(x, y, layer) || (cnt == 2 && effectflag(x + 8, y, layer));
6937 99567344 }
6938
6939 // used by mapdata->isSolid(x,y) in ZScript
6940 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
6941 {
6942 int x = zx.getRound(), y = zy.getRound();
6943 {
6944 int max_x = 256;
6945 int max_y = 176;
6946 if (!get_qr(qr_LTTPWALK))
6947 {
6948 max_x -= 7;
6949 max_y -= 7;
6950 }
6951 if (x < 0 || y < 0) return false;
6952 if (x >= max_x) return false;
6953 if (x >= max_x - 8 && cnt == 2) return false;
6954 if (y >= max_y) return false;
6955 }
6956
6957 const mapscr *s1, *s2;
6958
6959 if ( m->layermap[0] > 0 )
6960 {
6961 s1 = get_canonical_scr(m->layermap[0], m->layerscreen[0]);
6962 }
6963 else s1 = m;
6964
6965 if ( m->layermap[1] > 0 )
6966 {
6967 s2 = get_canonical_scr(m->layermap[1], m->layerscreen[1]);
6968 }
6969 else s2 = m;
6970
6971 zfix unused;
6972 return _walkflag_new(m, s1, s2, x, y, unused, false) || (cnt != 1 && _walkflag_new(m, s1, s2, x + 8, y, unused, false));
6973 }
6974
6975 bool _walkflag_layer(zfix_round x, zfix_round y, int32_t layer, int32_t cnt)
6976 {
6977 DCHECK_LAYER_NEG1_INDEX(layer);
6978 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
6979 if (!m->is_valid()) return false;
6980 return _walkflag_layer(x, y, cnt, m);
6981 }
6982
6983 static bool _walkflag_layer_new(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m, int max_x, int max_y)
6984 {
6985 int x = zx.getRound(), y = zy.getRound();
6986
6987 if (!get_qr(qr_LTTPWALK))
6988 {
6989 max_x -= 7;
6990 max_y -= 7;
6991 }
6992 if (x < 0 || y < 0) return false;
6993 if (x >= max_x) return false;
6994 if (x >= max_x - 8 && cnt == 2) return false;
6995 if (y >= max_y) return false;
6996
6997 if(!m) return true;
6998
6999 int pos = COMBOPOS(x%256, y%176);
7000 const newcombo* c = &combobuf[m->data[pos]];
7001 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
7002 int32_t b=1;
7003
7004 if(x&8) b<<=2;
7005
7006 if(y&8) b<<=1;
7007
7008 if((c->walk&b) && !dried)
7009 return true;
7010
7011 if(cnt==1) return false;
7012
7013 ++pos;
7014
7015 if(!(x&8))
7016 b<<=2;
7017 else
7018 {
7019 c = &combobuf[m->data[pos]];
7020 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7021 b=1;
7022
7023 if(y&8) b<<=1;
7024 }
7025
7026 return (c->walk&b) ? !dried : false;
7027 }
7028
7029 //Only check the given mapscr*, not its layer 1&2
7030 bool _walkflag_layer(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7031 {
7032 return _walkflag_layer_new(zx, zy, cnt, m, world_w, world_h);
7033 }
7034
7035 bool _walkflag_layer_scrolling(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7036 {
7037 return _walkflag_layer_new(zx, zy, cnt, m, scrolling_region.width, scrolling_region.height);
7038 }
7039
7040 297849 bool _effectflag_layer(int32_t x, int32_t y, int32_t layer, int32_t cnt, bool notLink)
7041 {
7042 DCHECK_LAYER_NEG1_INDEX(layer);
7043 297849 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
7044
2/2
✓ Branch 0 taken 1762 times.
✓ Branch 1 taken 296087 times.
297849 if (!m->is_valid()) return false;
7045 296087 return _effectflag_layer(x, y, cnt, m, notLink);
7046 297849 }
7047
7048 361053 bool _effectflag_layer(int32_t x,int32_t y,int32_t cnt, mapscr* m, bool notLink)
7049 {
7050 361053 int max_x = world_w;
7051 361053 int max_y = world_h;
7052
3/4
✓ Branch 0 taken 50002 times.
✓ Branch 1 taken 311051 times.
✓ Branch 2 taken 50002 times.
✗ Branch 3 not taken.
361053 if (!get_qr(qr_LTTPWALK) && !notLink)
7053 {
7054 max_x -= 7;
7055 max_y -= 7;
7056 }
7057
2/4
✓ Branch 0 taken 361053 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 361053 times.
361053 if (x < 0 || y < 0) return false;
7058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 361053 times.
361053 if (x >= max_x) return false;
7059
3/4
✓ Branch 0 taken 1209 times.
✓ Branch 1 taken 359844 times.
✓ Branch 2 taken 1209 times.
✗ Branch 3 not taken.
361053 if (x >= max_x - 8 && cnt == 2) return false;
7060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 361053 times.
361053 if (y >= max_y) return false;
7061
7062
1/2
✓ Branch 0 taken 361053 times.
✗ Branch 1 not taken.
361053 if (!m) return true;
7063
7064 361053 int pos = COMBOPOS(x%256, y%176);
7065 361053 const newcombo* c = &combobuf[m->data[pos]];
7066
3/4
✓ Branch 0 taken 360672 times.
✓ Branch 1 taken 381 times.
✓ Branch 2 taken 381 times.
✗ Branch 3 not taken.
361434 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
7067 361053 int32_t b=1;
7068
7069
2/2
✓ Branch 0 taken 196756 times.
✓ Branch 1 taken 164297 times.
361053 if(x&8) b<<=2;
7070
7071
2/2
✓ Branch 0 taken 139177 times.
✓ Branch 1 taken 221876 times.
361053 if(y&8) b<<=1;
7072
7073
3/4
✓ Branch 0 taken 292059 times.
✓ Branch 1 taken 68994 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 292059 times.
361053 if(((c->walk>>4)&b) && !dried)
7074 292059 return true;
7075
7076
1/2
✓ Branch 0 taken 68994 times.
✗ Branch 1 not taken.
68994 if(cnt==1) return false;
7077
7078 ++pos;
7079
7080 if(!(x&8))
7081 b<<=2;
7082 else
7083 {
7084 c = &combobuf[m->data[pos]];
7085 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7086 b=1;
7087
7088 if(y&8) b<<=1;
7089 }
7090
7091 return ((c->walk>>4)&b) ? !dried : false;
7092 361053 }
7093
7094 812605 bool water_walkflag(int32_t x, int32_t y, int32_t cnt)
7095 {
7096 812605 int max_x = world_w;
7097 812605 int max_y = world_h;
7098
2/2
✓ Branch 0 taken 117367 times.
✓ Branch 1 taken 695238 times.
812605 if (!get_qr(qr_LTTPWALK))
7099 {
7100 695238 max_x -= 7;
7101 695238 max_y -= 7;
7102 695238 }
7103
2/4
✓ Branch 0 taken 812605 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 812605 times.
812605 if (x < 0 || y < 0) return false;
7104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
812605 if (x >= max_x) return false;
7105
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
812605 if (x >= max_x - 8 && cnt == 2) return false;
7106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
812605 if (y >= max_y) return false;
7107
7108
3/4
✓ Branch 0 taken 16825 times.
✓ Branch 1 taken 795780 times.
✓ Branch 2 taken 795780 times.
✗ Branch 3 not taken.
812605 return water_walkflag(x, y) || (cnt != 1 && water_walkflag(x + 8, y));
7109 812605 }
7110
7111 812605 bool water_walkflag(int32_t x, int32_t y)
7112 {
7113 812605 const newcombo& c = combobuf[MAPCOMBO2(-1, x, y)];
7114 812605 const newcombo& c1 = combobuf[MAPCOMBO2(0, x, y)];
7115 812605 const newcombo& c2 = combobuf[MAPCOMBO2(1, x, y)];
7116
7117 812605 int32_t b=1;
7118
2/2
✓ Branch 0 taken 414677 times.
✓ Branch 1 taken 397928 times.
812605 if(x&8) b<<=2;
7119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
812605 if(y&8) b<<=1;
7120
7121
2/2
✓ Branch 0 taken 26377 times.
✓ Branch 1 taken 786228 times.
812605 if(get_qr(qr_NO_SOLID_SWIM))
7122 {
7123
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 26245 times.
26377 if(c.walk&b)
7124 132 return true;
7125
7126
2/2
✓ Branch 0 taken 292 times.
✓ Branch 1 taken 25953 times.
26245 if(c1.walk&b)
7127 292 return true;
7128
7129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25953 times.
25953 if(c2.walk&b)
7130 return true;
7131 25953 }
7132 else
7133 {
7134
4/4
✓ Branch 0 taken 36133 times.
✓ Branch 1 taken 750095 times.
✓ Branch 2 taken 19762 times.
✓ Branch 3 taken 16371 times.
786228 if((c.walk&b) && !iswater_type(c.type))
7135 16371 return true;
7136
7137
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 769840 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
769857 if((c1.walk&b) && !iswater_type(c1.type))
7138 17 return true;
7139
7140
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 769827 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
769840 if((c2.walk&b) && !iswater_type(c2.type))
7141 13 return true;
7142 }
7143
7144 795780 return false;
7145 812605 }
7146
7147 564224 bool hit_walkflag(int32_t x,int32_t y,int32_t cnt)
7148 {
7149
2/2
✓ Branch 0 taken 91107 times.
✓ Branch 1 taken 473117 times.
564224 if(dlevel)
7150
8/8
✓ Branch 0 taken 471712 times.
✓ Branch 1 taken 1405 times.
✓ Branch 2 taken 468517 times.
✓ Branch 3 taken 3195 times.
✓ Branch 4 taken 466857 times.
✓ Branch 5 taken 1660 times.
✓ Branch 6 taken 4199 times.
✓ Branch 7 taken 462658 times.
473117 if(x<32 || y<40 || (x+(cnt-1)*8)>=world_w-32 || y>=world_h-32)
7151 10459 return true;
7152
7153
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 553763 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
553765 if(blockpath && y<((get_qr(qr_LTTPCOLLISION))?80:88))
7154 return true;
7155
7156
8/8
✓ Branch 0 taken 553492 times.
✓ Branch 1 taken 273 times.
✓ Branch 2 taken 553259 times.
✓ Branch 3 taken 233 times.
✓ Branch 4 taken 553050 times.
✓ Branch 5 taken 209 times.
✓ Branch 6 taken 346 times.
✓ Branch 7 taken 552704 times.
553765 if(x<16 || y<16 || (x+(cnt-1)*8)>=world_w-16 || y>=world_h-16)
7157 1061 return true;
7158
7159 // for(int32_t i=0; i<4; i++)
7160
4/4
✓ Branch 0 taken 841 times.
✓ Branch 1 taken 551863 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 805 times.
552704 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7161 36 return true;
7162
7163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552668 times.
552668 if (collide_object(x, y,cnt*8, 1))
7164 return true;
7165
7166 552668 return _walkflag(x,y,cnt);
7167 564224 }
7168
7169 12110 bool solpush_walkflag(int32_t x, int32_t y, int32_t cnt, solid_object const* ign)
7170 {
7171 // 16 pixel buffer to account for slopes that are on bordering screens.
7172
4/8
✓ Branch 0 taken 12110 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12110 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12110 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12110 times.
12110 if(x<0 || y<0 || x>=world_w+16 || y>=world_h+16)
7173 return true;
7174
7175 // for(int32_t i=0; i<4; i++)
7176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12110 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7177 return true;
7178
7179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
12110 if (collide_object(x, y,cnt*8, 1, ign))
7180 return true;
7181
7182 12110 return _walkflag(x,y,cnt);
7183 12110 }
7184
7185 37844 void map_bkgsfx(bool on)
7186 {
7187
2/2
✓ Branch 0 taken 37823 times.
✓ Branch 1 taken 21 times.
37844 if(on)
7188 {
7189 37823 cont_sfx(hero_scr->oceansfx);
7190
7191
4/4
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 37456 times.
✓ Branch 2 taken 313 times.
✓ Branch 3 taken 54 times.
37823 if(hero_scr->bosssfx && !(game->lvlitems[dlevel]&liBOSS))
7192 313 cont_sfx(hero_scr->bosssfx);
7193 37823 }
7194 else
7195 {
7196 21 adjust_sfx(hero_scr->oceansfx,128,false);
7197 21 adjust_sfx(hero_scr->bosssfx,128,false);
7198
7199
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 21 times.
135 for(int32_t i=0; i<guys.Count(); i++)
7200 {
7201
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 84 times.
114 if(((enemy*)guys.spr(i))->bgsfx)
7202 84 stop_sfx(((enemy*)guys.spr(i))->bgsfx);
7203 114 }
7204 }
7205 37844 }
7206
7207 239 void toggle_switches(dword flags, bool entry)
7208 {
7209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 if(!flags) return; //No flags to toggle
7210
7211 478 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7212 239 toggle_switches(flags, entry, create_screen_handles(scr));
7213 239 });
7214 239 }
7215 54047 void toggle_switches(dword flags, bool entry, const screen_handles_t& screen_handles)
7216 {
7217
2/2
✓ Branch 0 taken 737 times.
✓ Branch 1 taken 53310 times.
54047 if(!flags) return; //No flags to toggle
7218
7219 737 mapscr* m = screen_handles[0].base_scr;
7220 737 int screen = m->screen;
7221 737 bool is_active_screen = is_in_current_region(m);
7222
7223 305041 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
7224 304304 byte togglegrid[176] = {0};
7225 304304 mapscr* scr = rpos_handle.scr;
7226 304304 int lyr = rpos_handle.layer;
7227 304304 int pos = rpos_handle.pos;
7228 304304 newcombo const& cmb = combobuf[scr->data[pos]];
7229
2/2
✓ Branch 0 taken 39424 times.
✓ Branch 1 taken 264880 times.
304304 if(is_active_screen)
7230
2/2
✓ Branch 0 taken 264880 times.
✓ Branch 1 taken 102893 times.
367773 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7231 {
7232 102893 auto& trig = cmb.triggers[idx];
7233
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 102893 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
102893 if((trig.triggerflags[3] & combotriggerTRIGLEVELSTATE) && trig.trig_lstate < 32)
7234 if(flags&(1<<trig.trig_lstate))
7235 {
7236 auto oldcombo = rpos_handle.data();
7237 do_trigger_combo(rpos_handle, idx, ctrigSWITCHSTATE);
7238 if(rpos_handle.data() != oldcombo) break;
7239 }
7240 367773 }
7241
3/4
✓ Branch 0 taken 303641 times.
✓ Branch 1 taken 663 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2760 times.
304304 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32
7242
2/2
✓ Branch 0 taken 2760 times.
✓ Branch 1 taken 301544 times.
304304 && !(cmb.usrflags & cflag11)) //global state
7243 {
7244
2/2
✓ Branch 0 taken 446 times.
✓ Branch 1 taken 2314 times.
2760 if(flags&(1<<cmb.attribytes[0]))
7245 {
7246 2314 set<int32_t> oldData;
7247 //Increment the combo/cset by the attributes
7248 2314 int32_t cmbofs = (cmb.attributes[0]/10000L);
7249 2314 int32_t csofs = (cmb.attributes[1]/10000L);
7250
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 oldData.insert(scr->data[pos]);
7251
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7252 2314 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7253
4/4
✓ Branch 0 taken 1435 times.
✓ Branch 1 taken 879 times.
✓ Branch 2 taken 1197 times.
✓ Branch 3 taken 238 times.
2314 if(entry && (cmb.usrflags&cflag8))
7254 {
7255 238 newcombo const* tmp = &combobuf[scr->data[pos]];
7256
2/4
✓ Branch 0 taken 238 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 238 times.
✗ Branch 3 not taken.
238 while(tmp->can_cycle())
7257 {
7258 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7259 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7260 if(oldData.find(cid) != oldData.end())
7261 break;
7262
7263 scr->data[pos] = cid;
7264 if(!(tmp->animflags & AF_CYCLENOCSET))
7265 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7266 oldData.insert(cid);
7267 tmp = &combobuf[cid];
7268 }
7269 238 }
7270 2314 int32_t cmbid = scr->data[pos];
7271
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 2273 times.
2314 if(combobuf[cmbid].animflags & AF_CYCLE)
7272 {
7273 41 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7274 41 combobuf[cmbid].cur_frame=0;
7275 41 combobuf[cmbid].aclk = 0;
7276
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 combo_caches::drawing.refresh(cmbid);
7277 41 }
7278 2314 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7279
2/2
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 1803 times.
2314 if(cmb.type == cCSWITCH) return; //Switches don't toggle other layers
7280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2147 times.
2147 for(int32_t lyr2 = 0; lyr2 < 7; ++lyr2) //Toggle same pos on other layers, if flag set
7281 {
7282
2/2
✓ Branch 0 taken 1671 times.
✓ Branch 1 taken 476 times.
2147 if(lyr==lyr2) return;
7283
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 344 times.
476 if(!(cmb.usrflags&(1<<lyr2))) return;
7284
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(togglegrid[pos]&(1<<lyr2)) return;
7285
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
344 mapscr* scr_2 = (lyr2 ? get_scr_layer(screen, lyr2) : m);
7286
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(!scr_2->data[pos]) //Don't increment empty space
7287 return;
7288 344 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7289
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
344 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK) && !(cmb.usrflags & cflag11)
7290 && cmb_2.attribytes[0] < 32 && (flags&(1<<cmb_2.attribytes[0])))
7291 return; //This is a switch/block that will be hit later in the loop!
7292 344 set<int32_t> oldData2;
7293 //Increment the combo/cset by the original cmb's attributes
7294
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 oldData2.insert(scr_2->data[pos]);
7295
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7296 344 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7297
3/4
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
344 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7298 {
7299 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7300 while(tmp->can_cycle())
7301 {
7302 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7303 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7304 if(oldData2.find(cid) != oldData2.end())
7305 break;
7306
7307 scr_2->data[pos] = cid;
7308 if(!(tmp->animflags & AF_CYCLENOCSET))
7309 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7310 oldData2.insert(cid);
7311 tmp = &combobuf[cid];
7312 }
7313 }
7314 344 int32_t cmbid2 = scr_2->data[pos];
7315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
344 if(combobuf[cmbid2].animflags & AF_CYCLE)
7316 {
7317 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7318 combobuf[cmbid2].cur_frame=0;
7319 combobuf[cmbid2].aclk = 0;
7320 combo_caches::drawing.refresh(cmbid2);
7321 }
7322 344 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7323 344 }
7324
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2314 times.
✗ Branch 2 not taken.
2314 }
7325 446 }
7326 304304 });
7327
7328
3/4
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 519 times.
✗ Branch 3 not taken.
737 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7329 {
7330 newcombo const& cmb = combobuf[mblock2.bcombo];
7331 if(!(cmb.usrflags & cflag11) && (cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32)
7332 {
7333 if(flags&(1<<cmb.attribytes[0]))
7334 {
7335 //Increment the combo/cset by the attributes
7336 int32_t cmbofs = (cmb.attributes[0]/10000L);
7337 int32_t csofs = (cmb.attributes[1]/10000L);
7338 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7339 mblock2.cs = (mblock2.cs + csofs) & 15;
7340 int32_t cmbid = mblock2.bcombo;
7341 if(combobuf[cmbid].animflags & AF_CYCLE)
7342 {
7343 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7344 combobuf[cmbid].cur_frame=0;
7345 combobuf[cmbid].aclk = 0;
7346 combo_caches::drawing.refresh(cmbid);
7347 }
7348 }
7349 }
7350 }
7351
7352
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 513 times.
737 if (is_active_screen)
7353 {
7354 513 int screen_index_offset = get_region_screen_offset(m->screen);
7355 513 word c = m->numFFC();
7356
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 513 times.
847 for (int q = 0; q < c; ++q)
7357 {
7358 334 auto ffc_handle = *m->getFFCHandle(q, screen_index_offset);
7359 334 auto& cmb = ffc_handle.combo();
7360
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 29 times.
363 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7361 {
7362 29 auto& trig = cmb.triggers[idx];
7363
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
29 if((trig.triggerflags[3] & combotriggerTRIGLEVELSTATE) && trig.trig_lstate < 32)
7364 if(flags&(1<<trig.trig_lstate))
7365 {
7366 auto oldcombo = ffc_handle.data();
7367 do_trigger_combo(ffc_handle, idx, ctrigSWITCHSTATE);
7368 if(ffc_handle.data() != oldcombo) break;
7369 }
7370 29 }
7371 334 }
7372 513 }
7373 54047 }
7374
7375 void toggle_gswitches(int32_t state, bool entry)
7376 {
7377 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7378 toggle_gswitches(state, entry, create_screen_handles(scr));
7379 });
7380 }
7381 void toggle_gswitches(int32_t state, bool entry, const screen_handles_t& screen_handles)
7382 {
7383 bool states[256] = {false};
7384 states[state] = true;
7385 toggle_gswitches(states, entry, screen_handles);
7386 }
7387 15219324 void toggle_gswitches(bool* states, bool entry, const screen_handles_t& screen_handles)
7388 {
7389
1/2
✓ Branch 0 taken 15219324 times.
✗ Branch 1 not taken.
15219324 if(!states) return;
7390
7391 15219324 auto& combo_cache = combo_caches::gswitch;
7392 15219324 mapscr* base_scr = screen_handles[0].base_scr;
7393 15219324 int screen = base_scr->screen;
7394 15219324 bool is_active_screen = is_in_current_region(base_scr);
7395 15219324 byte togglegrid[176] = {0};
7396
2/2
✓ Branch 0 taken 15219324 times.
✓ Branch 1 taken 106535268 times.
121754592 for(int32_t lyr = 0; lyr <= 6; ++lyr)
7397 {
7398 106535268 mapscr* scr = screen_handles[lyr].scr;
7399
2/2
✓ Branch 0 taken 74203033 times.
✓ Branch 1 taken 32332235 times.
106535268 if (!scr)
7400 74203033 continue;
7401
7402
2/2
✓ Branch 0 taken 5690473360 times.
✓ Branch 1 taken 32332235 times.
5722805595 for(int32_t pos = 0; pos < 176; ++pos)
7403 {
7404 5690473360 int cid = scr->data[pos];
7405 5690473360 auto& mini_cmb = combo_cache.minis[cid];
7406
7407
2/2
✓ Branch 0 taken 93474656 times.
✓ Branch 1 taken 5596998704 times.
5690473360 if (is_active_screen)
7408 {
7409
2/2
✓ Branch 0 taken 5596996822 times.
✓ Branch 1 taken 1882 times.
5596998704 if (mini_cmb.trigger_global_state)
7410 {
7411 1882 auto& cmb = combobuf[cid];
7412
2/2
✓ Branch 0 taken 1882 times.
✓ Branch 1 taken 1882 times.
3764 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7413 {
7414 1882 auto& trig = cmb.triggers[idx];
7415
2/4
✓ Branch 0 taken 1882 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1882 times.
✗ Branch 3 not taken.
1882 if ((trig.triggerflags[3] & combotriggerTRIGGLOBALSTATE) && states[trig.trig_gstate])
7416 {
7417 auto rpos_handle = get_rpos_handle_for_screen(screen, lyr, pos);
7418 do_trigger_combo(rpos_handle, idx, ctrigSWITCHSTATE);
7419 if(rpos_handle.data() != cid) break;
7420 }
7421 1882 }
7422 1882 }
7423 5596998704 }
7424
7425
2/2
✓ Branch 0 taken 40395 times.
✓ Branch 1 taken 5690432965 times.
5690473360 if (!mini_cmb.has_global_state)
7426 5690432965 continue;
7427
7428 40395 newcombo const& cmb = combobuf[cid];
7429
2/4
✓ Branch 0 taken 40395 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40395 times.
40395 if(cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK)
7430 {
7431 if(states[cmb.attribytes[0]])
7432 {
7433 set<int32_t> oldData;
7434 //Increment the combo/cset by the attributes
7435 int32_t cmbofs = (cmb.attributes[0]/10000L);
7436 int32_t csofs = (cmb.attributes[1]/10000L);
7437 oldData.insert(scr->data[pos]);
7438 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7439 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7440 if(entry && (cmb.usrflags&cflag8))
7441 {
7442 newcombo const* tmp = &combobuf[scr->data[pos]];
7443 while(tmp->can_cycle())
7444 {
7445 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7446 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7447 if(oldData.find(cid) != oldData.end())
7448 break;
7449 scr->data[pos] = cid;
7450 if(!(tmp->animflags & AF_CYCLENOCSET))
7451 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7452 oldData.insert(cid);
7453 tmp = &combobuf[cid];
7454 }
7455 }
7456 int32_t cmbid = scr->data[pos];
7457 if(combobuf[cmbid].animflags & AF_CYCLE)
7458 {
7459 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7460 combobuf[cmbid].cur_frame=0;
7461 combobuf[cmbid].aclk = 0;
7462 combo_caches::drawing.refresh(cmbid);
7463 }
7464 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7465 if(cmb.type == cCSWITCH) continue; //Switches don't toggle other layers
7466 for(int32_t lyr2 = 0; lyr2 <= 6; ++lyr2) //Toggle same pos on other layers, if flag set
7467 {
7468 if(lyr==lyr2) continue;
7469 if(!(cmb.usrflags&(1<<lyr2))) continue;
7470 if(togglegrid[pos]&(1<<lyr2)) continue;
7471 mapscr* scr_2 = lyr2 == 0 ? base_scr : get_scr_layer_valid(screen, lyr2);
7472 if(!scr_2 || !scr_2->data[pos]) //Don't increment empty space
7473 continue;
7474 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7475 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK)
7476 && (cmb_2.usrflags & cflag11) && (states[cmb_2.attribytes[0]]))
7477 continue; //This is a switch/block that will be hit later in the loop!
7478 set<int32_t> oldData2;
7479 //Increment the combo/cset by the original cmb's attributes
7480 oldData2.insert(scr_2->data[pos]);
7481 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7482 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7483 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7484 {
7485 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7486 while(tmp->can_cycle())
7487 {
7488 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7489 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7490 if(oldData2.find(cid) != oldData2.end())
7491 break;
7492 scr_2->data[pos] = cid;
7493 if(!(tmp->animflags & AF_CYCLENOCSET))
7494 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7495 oldData2.insert(cid);
7496 tmp = &combobuf[cid];
7497 }
7498 }
7499 int32_t cmbid2 = scr_2->data[pos];
7500 if(combobuf[cmbid2].animflags & AF_CYCLE)
7501 {
7502 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7503 combobuf[cmbid2].cur_frame=0;
7504 combobuf[cmbid2].aclk = 0;
7505 combo_caches::drawing.refresh(cmbid2);
7506 }
7507 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7508 }
7509 }
7510 }
7511 40395 }
7512 32332235 }
7513
7514
4/4
✓ Branch 0 taken 552060 times.
✓ Branch 1 taken 14667264 times.
✓ Branch 2 taken 4744 times.
✓ Branch 3 taken 547316 times.
15219324 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7515 {
7516 4744 newcombo const& cmb = combobuf[mblock2.bcombo];
7517
2/4
✓ Branch 0 taken 4744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4744 times.
✗ Branch 3 not taken.
4744 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && (cmb.usrflags & cflag11))
7518 {
7519 if(states[cmb.attribytes[0]])
7520 {
7521 //Increment the combo/cset by the attributes
7522 int32_t cmbofs = (cmb.attributes[0]/10000L);
7523 int32_t csofs = (cmb.attributes[1]/10000L);
7524 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7525 mblock2.cs = (mblock2.cs + csofs) & 15;
7526 int32_t cmbid = mblock2.bcombo;
7527 if(combobuf[cmbid].animflags & AF_CYCLE)
7528 {
7529 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7530 combobuf[cmbid].cur_frame=0;
7531 combobuf[cmbid].aclk = 0;
7532 combo_caches::drawing.refresh(cmbid);
7533 }
7534 }
7535 }
7536 4744 }
7537
7538
2/2
✓ Branch 0 taken 413475 times.
✓ Branch 1 taken 14805849 times.
15219324 if(is_active_screen)
7539 {
7540 14805849 int screen_index_offset = get_region_screen_offset(screen);
7541 14805849 word c = base_scr->numFFC();
7542
2/2
✓ Branch 0 taken 441728384 times.
✓ Branch 1 taken 14805849 times.
456534233 for (int q = 0; q < c; ++q)
7543 {
7544 441728384 auto ffc_handle = *base_scr->getFFCHandle(q, screen_index_offset);
7545 441728384 int cid = ffc_handle.data();
7546 // auto& mini_cmb = combo_cache.minis[cid];
7547 // if (mini_cmb.trigger_global_state)
7548 441728384 auto& cmb = combobuf[cid];
7549
2/2
✓ Branch 0 taken 441728384 times.
✓ Branch 1 taken 228788 times.
441957172 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7550 {
7551 228788 auto& trig = cmb.triggers[idx];
7552
1/2
✓ Branch 0 taken 228788 times.
✗ Branch 1 not taken.
228788 if (states[trig.trig_gstate])
7553 do_trigger_combo(ffc_handle, idx, ctrigSWITCHSTATE);
7554
1/2
✓ Branch 0 taken 228788 times.
✗ Branch 1 not taken.
228788 if(ffc_handle.data() != cid) break;
7555 228788 }
7556 441728384 }
7557 14805849 }
7558 15219324 }
7559 53808 void toggle_gswitches_load(const screen_handles_t& screen_handles)
7560 {
7561 bool states[256];
7562
2/2
✓ Branch 0 taken 13774848 times.
✓ Branch 1 taken 53808 times.
13828656 for(auto q = 0; q < 256; ++q)
7563 {
7564 13774848 states[q] = game->gswitch_timers[q] != 0;
7565 13774848 }
7566 53808 toggle_gswitches(states, true, screen_handles);
7567 53808 }
7568 14776148 void run_gswitch_timers()
7569 {
7570 14776148 bool states[256] = {false};
7571 14776148 auto& m = game->gswitch_timers.mut_inner();
7572
2/2
✓ Branch 0 taken 3779128320 times.
✓ Branch 1 taken 14776148 times.
3793904468 for(auto it = m.begin(); it != m.end();)
7573 {
7574
1/2
✓ Branch 0 taken 3779128320 times.
✗ Branch 1 not taken.
3779128320 if(it->second > 0)
7575 if(!--it->second)
7576 {
7577 states[it->first] = true;
7578 it = m.erase(it);
7579 continue;
7580 }
7581 3779128320 ++it;
7582 }
7583 29941664 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7584 15165516 toggle_gswitches(states, false, create_screen_handles(scr));
7585 15165516 });
7586 14776148 }
7587 1117 void onload_gswitch_timers() //Reset all timers that were counting down, no trigger necessary
7588 {
7589
2/2
✓ Branch 0 taken 285952 times.
✓ Branch 1 taken 1117 times.
287069 for(auto q = 0; q < 256; ++q)
7590 {
7591
1/2
✓ Branch 0 taken 285952 times.
✗ Branch 1 not taken.
285952 if(game->gswitch_timers[q] > 0)
7592 game->gswitch_timers[q] = 0;
7593 285952 }
7594 1117 }
7595
7596 /**** View Map ****/
7597
7598 int32_t mapres = 0;
7599 int32_t view_map_show_mode = 3;
7600
7601 124544 bool displayOnMap(int32_t x, int32_t y)
7602 {
7603 124544 int32_t s = (y<<4) + x;
7604 124544 int mi = mapind(cur_map, s);
7605
2/2
✓ Branch 0 taken 67891 times.
✓ Branch 1 taken 56653 times.
124544 if (!(game->maps[mi]&mVISITED))
7606 67891 return false;
7607
7608 // Don't display if not part of DMap
7609
4/4
✓ Branch 0 taken 15628 times.
✓ Branch 1 taken 41025 times.
✓ Branch 2 taken 4655 times.
✓ Branch 3 taken 4311 times.
65619 if(((DMaps[cur_dmap].flags&dmfDMAPMAP) &&
7610
1/2
✓ Branch 0 taken 15628 times.
✗ Branch 1 not taken.
15628 (DMaps[cur_dmap].type != dmOVERW) &&
7611
2/2
✓ Branch 0 taken 12495 times.
✓ Branch 1 taken 3133 times.
15628 !(x >= DMaps[cur_dmap].xoff &&
7612
2/2
✓ Branch 0 taken 8966 times.
✓ Branch 1 taken 3529 times.
12495 x < DMaps[cur_dmap].xoff+8 &&
7613 8966 DMaps[cur_dmap].grid[y]&(128>>(x-DMaps[cur_dmap].xoff)))))
7614 10973 return false;
7615 else
7616 45680 return true;
7617 124544 }
7618
7619 973 void ViewMap()
7620 {
7621 973 ViewingMap = true;
7622
7623 973 BITMAP* mappic = NULL;
7624 static double scales[17] =
7625 {
7626 0.03125, 0.04419, 0.0625, 0.08839, 0.125, 0.177, 0.25, 0.3535,
7627 0.50, 0.707, 1.0, 1.414, 2.0, 2.828, 4.0, 5.657, 8.0
7628 };
7629
7630 973 int32_t px = ((8-(cur_screen&15)) << 9) - 256;
7631 973 int32_t py = ((4-(cur_screen>>4)) * 352) - 176;
7632 973 int32_t lx = ((cur_screen&15)<<8) + HeroX()+8;
7633 973 int32_t ly = ((cur_screen>>4)*176) + HeroY()+8;
7634 973 int32_t sc = 6;
7635
7636 973 bool done=false, redraw=true;
7637
7638 973 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
7639
7640
1/2
✓ Branch 0 taken 973 times.
✗ Branch 1 not taken.
973 if(!mappic)
7641 {
7642 enter_sys_pal();
7643 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
7644 exit_sys_pal();
7645 return;
7646 }
7647
7648 973 clear_to_color(mappic, WHITE);
7649
7650 973 auto prev_viewport = viewport;
7651 973 viewport.x = 0;
7652 973 viewport.y = 0;
7653
7654 // draw the map
7655 973 BITMAP* screen_bmp = create_bitmap_ex(8, 256, 176);
7656 973 combotile_add_x = 256;
7657 973 combotile_add_y = 0;
7658
2/2
✓ Branch 0 taken 7784 times.
✓ Branch 1 taken 973 times.
8757 for(int32_t y=0; y<8; y++)
7659 {
7660
2/2
✓ Branch 0 taken 124544 times.
✓ Branch 1 taken 7784 times.
132328 for(int32_t x=0; x<16; x++)
7661 {
7662
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 78864 times.
124544 if (!displayOnMap(x, y))
7663 78864 continue;
7664
7665 45680 int screen = map_scr_xy_to_index(x, y);
7666 45680 auto scrs = loadscr2(screen);
7667 45680 mapscr* scr = &scrs[0];
7668
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!scr->is_valid())
7669 continue;
7670
7671 screen_handles_t screen_handles;
7672
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i <= 6; i++)
7673
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103790 times.
✓ Branch 3 taken 215970 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
7674
7675 45680 int xx = 0;
7676 45680 int yy = -playing_field_offset;
7677
7678
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 45660 times.
45680 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
7679 {
7680
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7681
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 do_ffc_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7682 20 }
7683
7684
2/2
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 45505 times.
45680 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
7685 {
7686
1/2
✓ Branch 0 taken 175 times.
✗ Branch 1 not taken.
175 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7687
1/2
✓ Branch 0 taken 175 times.
✗ Branch 1 not taken.
175 do_ffc_layer(screen_bmp, -3, screen_handles[0], xx, yy);
7688 175 }
7689
7690
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if(lenscheck(scr,0)) putscr(scr, screen_bmp, 0, 0);
7691
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 0, screen_handles[0], xx, yy);
7692
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[1], xx, yy);
7693
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 1, screen_handles[0], xx, yy);
7694
7695
2/2
✓ Branch 0 taken 45660 times.
✓ Branch 1 taken 20 times.
45680 if(!XOR((scr->flags7&fLAYER2BG), DMaps[cur_dmap].flags&dmfLAYER2BG))
7696 {
7697
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7698
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_ffc_layer(screen_bmp, 2, screen_handles[0], xx, yy);
7699 45660 }
7700
7701
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 putscrdoors(scr, screen_bmp, xx, yy);
7702
2/2
✓ Branch 0 taken 41678 times.
✓ Branch 1 taken 4002 times.
45680 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
7703 {
7704
1/2
✓ Branch 0 taken 41678 times.
✗ Branch 1 not taken.
41678 do_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7705
2/2
✓ Branch 0 taken 1782 times.
✓ Branch 1 taken 39896 times.
41678 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
7706 {
7707
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[1], xx, yy);
7708
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[2], xx, yy);
7709 1782 }
7710 41678 }
7711
7712
2/2
✓ Branch 0 taken 45505 times.
✓ Branch 1 taken 175 times.
45680 if(!XOR((scr->flags7&fLAYER3BG), DMaps[cur_dmap].flags&dmfLAYER3BG))
7713 {
7714
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7715
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_ffc_layer(screen_bmp, 3, screen_handles[0], xx, yy);
7716 45505 }
7717
7718
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[4], xx, yy);
7719
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 4, screen_handles[0], xx, yy);
7720
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7721
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 39896 times.
45680 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
7722 {
7723
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[1], xx, yy);
7724
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[2], xx, yy);
7725 5784 }
7726
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[5], xx, yy);
7727
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 5, screen_handles[0], xx, yy);
7728
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(replay_version_check(40))
7729 do_ffc_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7730
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[6], xx, yy);
7731
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 6, screen_handles[0], xx, yy);
7732
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 7, screen_handles[0], xx, yy);
7733
7734
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 stretch_blit(screen_bmp, mappic, 0, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
7735
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
45680 }
7736 7784 }
7737
7738 973 viewport = prev_viewport;
7739 973 combotile_add_x = 0;
7740 973 combotile_add_y = 0;
7741
7742 973 destroy_bitmap(screen_bmp);
7743 973 clear_keybuf();
7744 973 pause_all_sfx();
7745
7746 // view it
7747 973 int32_t delay = 0;
7748
7749 973 do
7750 {
7751
2/2
✓ Branch 0 taken 178717 times.
✓ Branch 1 taken 29891 times.
208608 if (replay_version_check(0, 11))
7752 29891 load_control_state();
7753
7754 208608 int32_t step = int32_t(16.0/scales[sc]);
7755 208608 step = (step>>1) + (step&1);
7756 208608 bool r = cRbtn();
7757
7758
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(cLbtn())
7759 {
7760 step <<= 2;
7761 delay = 0;
7762 }
7763
7764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208608 times.
208608 if(r)
7765 {
7766 if(rUp())
7767 {
7768 py+=step;
7769 redraw=true;
7770 }
7771
7772 if(rDown())
7773 {
7774 py-=step;
7775 redraw=true;
7776 }
7777
7778 if(rLeft())
7779 {
7780 px+=step;
7781 redraw=true;
7782 }
7783
7784 if(rRight())
7785 {
7786 px-=step;
7787 redraw=true;
7788 }
7789 }
7790 else
7791 {
7792
2/2
✓ Branch 0 taken 193729 times.
✓ Branch 1 taken 14879 times.
208608 if(Up())
7793 {
7794 14879 py+=step;
7795 14879 redraw=true;
7796 14879 }
7797
7798
2/2
✓ Branch 0 taken 193574 times.
✓ Branch 1 taken 15034 times.
208608 if(Down())
7799 {
7800 15034 py-=step;
7801 15034 redraw=true;
7802 15034 }
7803
7804
2/2
✓ Branch 0 taken 182159 times.
✓ Branch 1 taken 26449 times.
208608 if(Left())
7805 {
7806 26449 px+=step;
7807 26449 redraw=true;
7808 26449 }
7809
7810
2/2
✓ Branch 0 taken 182774 times.
✓ Branch 1 taken 25834 times.
208608 if(Right())
7811 {
7812 25834 px-=step;
7813 25834 redraw=true;
7814 25834 }
7815 }
7816
7817
2/2
✓ Branch 0 taken 187444 times.
✓ Branch 1 taken 21164 times.
208608 if(delay)
7818 21164 --delay;
7819 else
7820 {
7821 187444 bool a = cAbtn();
7822 187444 bool b = cBbtn();
7823
7824
3/4
✓ Branch 0 taken 1721 times.
✓ Branch 1 taken 185723 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1721 times.
187444 if(a && !b)
7825 {
7826
1/2
✓ Branch 0 taken 1721 times.
✗ Branch 1 not taken.
1721 sc=zc_min(sc+1,16);
7827 1721 delay=8;
7828 1721 redraw=true;
7829 1721 }
7830
7831
3/4
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 186517 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 927 times.
187444 if(b && !a)
7832 {
7833
2/2
✓ Branch 0 taken 926 times.
✓ Branch 1 taken 1 times.
927 sc=zc_max(sc-1,0);
7834 927 delay=8;
7835 927 redraw=true;
7836 927 }
7837 }
7838
7839
2/2
✓ Branch 0 taken 208597 times.
✓ Branch 1 taken 11 times.
208608 if(rPbtn())
7840 11 --view_map_show_mode;
7841
7842 208608 px = vbound(px,-4096,4096);
7843 208608 py = vbound(py,-1408,1408);
7844
7845 208608 double scale = scales[sc];
7846
7847
2/2
✓ Branch 0 taken 72838 times.
✓ Branch 1 taken 135770 times.
208608 if(!redraw)
7848 {
7849 135770 blit(scrollbuf_old,framebuf,256,0,0,0,256,232);
7850 135770 }
7851 else
7852 {
7853 72838 clear_to_color(framebuf,BLACK);
7854 145676 stretch_blit(mappic,framebuf,0,0,mappic->w,mappic->h,
7855 72838 int32_t(256+(int64_t(px)-mappic->w)*scale)/2,int32_t(224+(int64_t(py)-mappic->h)*scale)/2,
7856 72838 int32_t(mappic->w*scale),int32_t(mappic->h*scale));
7857
7858 72838 blit(framebuf,scrollbuf_old,0,0,256,0,256,232);
7859 72838 redraw=false;
7860 }
7861
7862 208608 int32_t x = int32_t(256+(px-((2048-int64_t(lx))*2))*scale)/2;
7863 208608 int32_t y = int32_t(224+(py-((704-int64_t(ly))*2))*scale)/2;
7864
7865
2/2
✓ Branch 0 taken 7466 times.
✓ Branch 1 taken 201142 times.
208608 if(view_map_show_mode&1)
7866 {
7867 201142 line(framebuf,x-7,y-7,x+7,y+7,(frame&3)+252);
7868 201142 line(framebuf,x+7,y-7,x-7,y+7,(frame&3)+252);
7869 201142 }
7870
7871
3/4
✓ Branch 0 taken 5600 times.
✓ Branch 1 taken 203008 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5600 times.
208608 if(view_map_show_mode&2 || r)
7872 203008 textprintf_ex(framebuf,font,224,216,WHITE,BLACK,"%1.2f",scale);
7873
7874
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(r)
7875 {
7876 textprintf_ex(framebuf,font,0,208,WHITE,BLACK,"m: %d %d",px,py);
7877 textprintf_ex(framebuf,font,0,216,WHITE,BLACK,"x: %d %d",x,y);
7878 }
7879
7880 208608 advanceframe(false, false);
7881
2/2
✓ Branch 0 taken 29891 times.
✓ Branch 1 taken 178717 times.
208608 if (replay_version_check(11))
7882 178717 load_control_state();
7883
7884
2/2
✓ Branch 0 taken 207636 times.
✓ Branch 1 taken 972 times.
208608 if(getInput(btnS, true, false, true)) //rSbtn
7885 972 done = true;
7886
7887
2/2
✓ Branch 0 taken 973 times.
✓ Branch 1 taken 207635 times.
417216 }
7888
2/2
✓ Branch 0 taken 972 times.
✓ Branch 1 taken 207636 times.
208608 while(!done && !Quit);
7889
7890 973 ViewingMap = false;
7891 973 destroy_bitmap(mappic);
7892 973 resume_all_sfx();
7893 973 }
7894
7895 1075 int32_t onViewMap()
7896 {
7897
4/6
✓ Branch 0 taken 1075 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1075 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 102 times.
✓ Branch 5 taken 973 times.
1075 if(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)
7898 {
7899 973 clear_to_color(framebuf,BLACK);
7900 973 textout_centre_ex(framebuf,font,"Drawing map...",128,108,WHITE,BLACK);
7901 973 advanceframe(true);
7902 973 ViewMap();
7903 973 }
7904
7905 1075 return D_O_K;
7906 }
7907
7908 35779575 bool isGrassType(int32_t type)
7909 {
7910
2/2
✓ Branch 0 taken 35103163 times.
✓ Branch 1 taken 676412 times.
35779575 switch(type)
7911 {
7912 case cTALLGRASS:
7913 case cTALLGRASSNEXT:
7914 case cTALLGRASSTOUCHY:
7915 676412 return true;
7916 }
7917
7918 35103163 return false;
7919 35779575 }
7920
7921 20914 bool isFlowersType(int32_t type)
7922 {
7923
2/2
✓ Branch 0 taken 16574 times.
✓ Branch 1 taken 4340 times.
20914 switch(type)
7924 {
7925 case cFLOWERS:
7926 case cFLOWERSTOUCHY:
7927 4340 return true;
7928 }
7929
7930 16574 return false;
7931 20914 }
7932
7933 bool isGenericType(int32_t type)
7934 {
7935 switch(type)
7936 {
7937 case cTRIGGERGENERIC:
7938 return true;
7939 }
7940
7941 return false;
7942 }
7943
7944 26056 bool isBushType(int32_t type)
7945 {
7946
2/2
✓ Branch 0 taken 20914 times.
✓ Branch 1 taken 5142 times.
26056 switch(type)
7947 {
7948 case cBUSH:
7949 case cBUSHNEXT:
7950 case cBUSHTOUCHY:
7951 case cBUSHNEXTTOUCHY:
7952
7953 5142 return true;
7954 }
7955
7956 20914 return false;
7957 26056 }
7958
7959 bool isSlashType(int32_t type)
7960 {
7961 switch(type)
7962 {
7963 case cSLASH:
7964 case cSLASHITEM:
7965 case cSLASHTOUCHY:
7966 case cSLASHITEMTOUCHY:
7967 case cSLASHNEXT:
7968 case cSLASHNEXTITEM:
7969 case cSLASHNEXTTOUCHY:
7970 case cSLASHNEXTITEMTOUCHY:
7971 return true;
7972 }
7973
7974 return false;
7975 }
7976
7977 15695 bool isCuttableNextType(int32_t type)
7978 {
7979
2/2
✓ Branch 0 taken 9788 times.
✓ Branch 1 taken 5907 times.
15695 switch(type)
7980 {
7981 case cSLASHNEXT:
7982 case cSLASHNEXTITEM:
7983 case cTALLGRASSNEXT:
7984 case cBUSHNEXT:
7985 case cSLASHNEXTTOUCHY:
7986 case cSLASHNEXTITEMTOUCHY:
7987 case cBUSHNEXTTOUCHY:
7988 5907 return true;
7989 }
7990
7991 9788 return false;
7992 15695 }
7993
7994 17546 bool isTouchyType(int32_t type)
7995 {
7996
2/2
✓ Branch 0 taken 6050 times.
✓ Branch 1 taken 11496 times.
17546 switch(type)
7997 {
7998 case cSLASHTOUCHY:
7999 case cSLASHITEMTOUCHY:
8000 case cBUSHTOUCHY:
8001 case cFLOWERSTOUCHY:
8002 case cTALLGRASSTOUCHY:
8003 case cSLASHNEXTTOUCHY:
8004 case cSLASHNEXTITEMTOUCHY:
8005 case cBUSHNEXTTOUCHY:
8006 11496 return true;
8007 }
8008
8009 6050 return false;
8010 17546 }
8011
8012 29324654 bool isCuttableType(int32_t type)
8013 {
8014
2/2
✓ Branch 0 taken 28875389 times.
✓ Branch 1 taken 449265 times.
29324654 switch(type)
8015 {
8016 case cSLASH:
8017 case cSLASHITEM:
8018 case cBUSH:
8019 case cFLOWERS:
8020 case cTALLGRASS:
8021 case cTALLGRASSNEXT:
8022 case cSLASHNEXT:
8023 case cSLASHNEXTITEM:
8024 case cBUSHNEXT:
8025
8026 case cSLASHTOUCHY:
8027 case cSLASHITEMTOUCHY:
8028 case cBUSHTOUCHY:
8029 case cFLOWERSTOUCHY:
8030 case cTALLGRASSTOUCHY:
8031 case cSLASHNEXTTOUCHY:
8032 case cSLASHNEXTITEMTOUCHY:
8033 case cBUSHNEXTTOUCHY:
8034 449265 return true;
8035 }
8036
8037 28875389 return false;
8038 29324654 }
8039
8040 17322 bool isCuttableItemType(int32_t type)
8041 {
8042
2/2
✓ Branch 0 taken 424 times.
✓ Branch 1 taken 16898 times.
17322 switch(type)
8043 {
8044 case cSLASHITEM:
8045 case cBUSH:
8046 case cFLOWERS:
8047 case cTALLGRASS:
8048 case cTALLGRASSNEXT:
8049 case cSLASHNEXTITEM:
8050 case cBUSHNEXT:
8051
8052 case cSLASHITEMTOUCHY:
8053 case cBUSHTOUCHY:
8054 case cFLOWERSTOUCHY:
8055 case cTALLGRASSTOUCHY:
8056 case cSLASHNEXTITEMTOUCHY:
8057 case cBUSHNEXTTOUCHY:
8058 16898 return true;
8059 }
8060
8061 424 return false;
8062 17322 }
8063
8064 66 bool is_push(mapscr* m, int32_t pos)
8065 {
8066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(m->sflag[pos]))
8067 return true;
8068 66 newcombo const& cmb = combobuf[m->data[pos]];
8069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(cmb.flag))
8070 return true;
8071
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 52 times.
66 if(cmb.type == cPUSHBLOCK)
8072 14 return true;
8073
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
52 if(cmb.type == cSWITCHHOOK && (cmb.usrflags&cflag7))
8074 return true; //Counts as 'pushblock' flag
8075 52 return false;
8076 66 }
8077
8078 411 static std::map<int, screen_state_t> screen_states;
8079
8080 35861 std::map<int, screen_state_t>& get_screen_states()
8081 {
8082 35861 return screen_states;
8083 }
8084
8085 44191005 screen_state_t& get_screen_state(int screen)
8086 {
8087 44191005 return screen_states[screen];
8088 }
8089
8090 576 void clear_screen_states()
8091 {
8092 576 screen_states.clear();
8093 576 }
8094
8095 1439 void screen_item_set_state(int screen, ScreenItemState state)
8096 {
8097 1439 get_screen_state(screen).item_state = state;
8098 1439 }
8099
8100 37016 void mark_visited(int screen)
8101 {
8102
2/2
✓ Branch 0 taken 475 times.
✓ Branch 1 taken 36541 times.
37016 if (screen < 0x80)
8103 {
8104
2/2
✓ Branch 0 taken 24617 times.
✓ Branch 1 taken 11924 times.
36541 if(DMaps[cur_dmap].flags&dmfVIEWMAP)
8105 11924 game->maps[mapind(cur_map, screen)] |= mVISITED;
8106
8107 36541 markBmap(-1, screen);
8108 36541 }
8109 37016 }
8110